Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught SyntaxError: Unexpected token < #18

Open
Jitra opened this Issue Feb 3, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Jitra
Copy link

Jitra commented Feb 3, 2019

I wanted to create an npm package that internally uses web worker. I got working configuration for that in the worker-loader package for webpack as follows.

{
  test: /\.worker\.js$/,
  use: {
    loader: 'worker-loader',
    options: {
      inline: true
    }
  }
}

then I could use my library in some react project like that

import {BoardGenerator} from '@yufuzu/shipbattle-board';
const generator = new BoardGenerator();

Board generator is my npm library that uses it's web worker.

When I switched to this plugin I get an error that it cannot find web worker. Everything compiles properly and I am able to see use it in live mode in the browser. (From this project npm start). Problem occurs only when I import that library in some other project.

Repo:
https://github.com/Jitra/shipbattle-generatorv2 working in here npm start
React repo importing npm package:
https://github.com/Jitra/react-shipbattle-generator-example not working here

Old version with worker-loader
https://github.com/Jitra/shipbattle-generator

@Jitra

This comment has been minimized.

Copy link
Author

Jitra commented Feb 11, 2019

I appreciate your work for using webworker with module imports. Any plans of supporting web workers that are imported from node_modules lib. Now there are two libraries:
worker-loader Works imported from node_modules, by inline:true, but no web worker type: module supported
worker-plugin supports worker type: module, but but not inlining as plugin above :(

I wish to switch from worker-loader to this plugin for module importing support in web workers but I stuck

@developit

This comment has been minimized.

Copy link
Member

developit commented Feb 19, 2019

Bundling a worker to a data URI is generally not a good idea. It's putting extra strain on the parser in the main thread for no reason.

I'm not sure there is a reasonable way to make this work - webpack's output isn't really designed to be nested inside another Webpack bundle, it breaks things like pathing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.