GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.92k stars 79 forks source link

Error when using NPM module with Rollup worker bundled #93

Closed a-type closed 3 years ago

a-type commented 4 years ago

I'm using this plugin with a Create-React-App based project (utilizing react-app-rewired to inject it into the Webpack plugin). So far that was working great.

I went to add use-cannon, however, and encountered a strange build error:

Failed to compile.

./node_modules/use-cannon/dist/Provider-f05cb643.js
Module parse failed: Cannot read property 'length' of undefined
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
TypeError: Cannot read property 'length' of undefined

Ultimately I've narrowed it down to worker-plugin. If I run my app without react-app-rewired (i.e. not adding the plugin), use-cannon works fine.

A minimal reproduction repo lives here. The error shows up when starting the project. You can switch the npm start script back to react-scripts start to see that it runs fine without worker-plugin.

There's probably something specifically off about the way worker-plugin tries to operate on the worker that's already taken care of within the built bundle of use-cannon.

Possible solutions:

  1. Add a way to omit node_modules dependencies from worker-plugin's processing
  2. Exclude specific NPM dependencies by name
  3. Make whatever processing is happening more fault-tolerant and just have it ignore the file if this error comes up
lucas-janon commented 3 years ago

For people searching for a temporary solution: downgrading to 4.0.3 worked (no pun intended) for me

ezforw commented 3 years ago

BTW, it seems it's also affecting Angular as well, the issue can be reproduced here https://github.com/angular/angular-cli/issues/19884

developit commented 3 years ago

This should be fixed by #94.