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 TypeError: Failed to construct 'Worker' #2

Closed
mizchi opened this issue Sep 19, 2018 · 6 comments
Closed

Uncaught TypeError: Failed to construct 'Worker' #2

mizchi opened this issue Sep 19, 2018 · 6 comments
Labels
bug Something isn't working

Comments

@mizchi
Copy link

mizchi commented Sep 19, 2018

I tried minimum example. (on Chrome 69/Mac)

// src/index.js
const worker = new Worker("./worker.js", { type: "module" });
worker.onmessage = event => {
  console.log("response: " + event.data);
};
worker.postMessage(0);
// webpack.config.js
const HTMLPlugin = require("html-webpack-plugin");
const WorkerPlugin = require("worker-plugin");

module.exports = {
  mode: process.env.NODE_ENV || "development",
  plugins: [new HTMLPlugin(), new WorkerPlugin()]
};

Compile success but I got this error on browser.

Uncaught TypeError: Failed to construct 'Worker': Module scripts are not supported on DedicatedWorker yet. You can try the feature with '--enable-experimental-web-platform-features' flag (see https://crbug.com/680046)
    at Object.<anonymous> (main.js:9346)
    at Object../src/index.js (main.js:9354)
    at __webpack_require__ (main.js:20)
    at Object.0 (main.js:9366)
    at __webpack_require__ (main.js:20)
    at ./node_modules/ansi-html/index.js.module.exports (main.js:84)
    at main.js:87

Build result is here

/* WEBPACK VAR INJECTION */(function(__webpack__worker__1) {const worker = new Worker(__webpack__worker__1, { type: "module" });
// ...

I tried enable-experimental-web-platform-features but it does not work too. (and ChromeCanary too)

I think, it is lack of some pre-conditions.

My full code is here https://github.com/mizchi-sandbox/try-worker-plugin

@e00dan
Copy link

e00dan commented Sep 19, 2018

Hitting the same problem.

@satya164
Copy link

satya164 commented Oct 6, 2018

I have the same problem. Looks like this plugin doesn't actually bundle the worker like worker-loader does. Is this a replacement for worker-loader or I am misunderstanding how this is supposed to work?

@developit
Copy link
Collaborator

The plugin does bundle. It's a direct replacement for worker-loader. Perhaps this is a bug.

@developit
Copy link
Collaborator

This should be fixed by 9178a29 :)

@developit developit added the bug Something isn't working label Oct 9, 2018
@e00dan
Copy link

e00dan commented Oct 9, 2018

This works indeed @developit. When can we expect new release? :)

When I try to install it using GitHub commit as NPM dependency I get error:

$ node --version
v8.12.0
$ npm --version
6.4.1
$ nvm --version
0.33.11
install
107.96s$ npm install
> worker-plugin@1.0.0 prepack /home/travis/.npm/_cacache/tmp/git-clone-dc3958f6
> npm run build
> worker-plugin@1.0.0 build /home/travis/.npm/_cacache/tmp/git-clone-dc3958f6
> microbundle --inline none --format cjs --no-compress src/*.js
sh: 1: microbundle: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! worker-plugin@1.0.0 build: `microbundle --inline none --format cjs --no-compress src/*.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the worker-plugin@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/travis/.npm/_logs/2018-10-09T14_54_49_901Z-debug.log

Full log: https://travis-ci.org/chronologic/eth-alarm-clock-dapp/builds/439176788

Dependency line:

"worker-plugin": "GoogleChromeLabs/worker-plugin#9178a29"

@developit
Copy link
Collaborator

Fix released in 1.1.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants