worker-loader icon indicating copy to clipboard operation
worker-loader copied to clipboard

Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor

Open adambyer opened this issue 3 years ago • 5 comments

  • Operating System: macOS Catalina 10.15.7
  • Node Version: v10.13.0
  • NPM Version: 6.14.9
  • webpack Version: 4.46.0
  • worker-loader Version: 3.0.8

Expected Behavior

Should get no errors and publicPath should work.

Actual Behavior

If I use webpack I get the following error when instantiating WORKER below... Uncaught TypeError: _dist_workers_worker_js__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor

If I import with worker-loader inline like import Worker from 'worker-loader!../../../dist/workers/worker.js' I don't get that error, but it doesn't seem that my publicPath in webpack is being applied because I get this error... `Security Error: Content at https://my-app.com may not load data from https://my-cdn.com/base/js/worker.bundle.worker.js.

Code

// webpack.config.js
{
    test: /\.worker\.js$/,
    use: {
        loader: 'worker-loader',
        options: {publicPath: '/workers/'},
    },
},
import Worker from '../../../dist/workers/worker.js'
const WORKER = new Worker()

adambyer avatar Feb 19 '21 01:02 adambyer

Unfortunately it is limitation https://github.com/webpack-contrib/worker-loader#cross-origin-policy, webpack v5 doesn't have this problem

alexander-akait avatar Feb 19 '21 11:02 alexander-akait

Thanks. The documentation you linked to is what I am trying to follow to get around the cross-origin issue. I've tried both recommended workarounds with no luck. Are you saying those workarounds require webpack v5?

adambyer avatar Feb 19 '21 18:02 adambyer

@adambyer Can you provide simple reproducible test repo?

alexander-akait avatar Feb 20 '21 12:02 alexander-akait

It seems related to the fact that your worker.js file is not exporting anything, but then you are importing it. I am having a similar issue when following the README examples.

afuggini avatar Feb 22 '21 21:02 afuggini

I have the same problem

marklsl avatar Jul 08 '21 13:07 marklsl