• Register
1 vote
659 views

Problem :

I am naïve to Webpack. As the Webpack does not support the native webworker syntax so currently I want to use a worker-loader npm module but because of some unknown reason t I am facing the below weird error.

“Cannot assign to read only property 'exports' of object '#<Object>'?”.

Kindly find the required webpack config below for your kind reference:

module.exports = {
    entry: "./app",
    output: {
        path: __dirname + "/build",
        filename: "bundle.js"
    },
    watch: true,
    module: {
        rules: [{
            test: /\.worker\.js$/,
            use: {
                loader: 'worker-loader'
            }
        }]
    }
}
Also kindly find the below my code which I think is responsible for the triggering of above mentioned error:
import Worker from '../workers/sim.js';
class MySynapse {
  // ...
}
module.exports = MySynapse;
I am trying to fix the above error from past couple of days. I have tried to do research on it also but still unable to understand the root cause of above error. Now I am in badly need of the expert advice to fix above error.
8 5 2
3,230 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

I know about this error very well you are getting current error as you must have mixed the CommonJS module.exports with ES Modules. To fix the error you must change your module.exports to the ES Module counterpart export default as shown below:

import Worker from '../workers/sim.js';
class MySynapse {
  // ...
}
export default MySynapse; // ES Module syntax
I hope it works for you.
8 4 1
5,680 points

Related questions

0 votes
1 answer 5 views
5 views
Problem: I'm using webpack, which, if I understand correctly, doesn't support native webworker syntax, so I'm trying to use the worker-loader npm module, but I'm getting a weird error. The module can be found here. My webpack config: module.exports = { entry: ... .exports = Synapse; Error: Cannot assign to read only property 'exports' of object '#<Object>'? which points to module.exports = Synapse
asked Apr 25 muktaa 34.6k points
0 votes
1 answer 61 views
61 views
I am tribuleing to assign read only property 'exports&rsquo; of object.
asked Sep 22, 2020 Daniel Anderson 4k points
0 votes
1 answer 14 views
14 views
Problem: Webpack - webpack-dev-server: command not found
asked Mar 15 ummesalma 29.2k points
0 votes
1 answer 827 views
827 views
Problem : I am running Laravel 5.4 on my Homestead vagrant box but when I want to run npm run production I am getting the following error block-scoped declarations (let, const, function, class) not yet supported outside strict mode.
asked Nov 14, 2019 peterlaw 6.9k points
1 vote
1 answer 8 views
8 views
Problem : I want to save images in Azure storage but I get the error message: TypeError: Cannot read property '1' of nullI can not understand to solve, Can anyone help?
asked Mar 21 Sabbir Hossain 14.6k points
1 vote
1 answer 112 views
112 views
Problem : How to fix this error: TypeError: Cannot read property 'path' of undefined
asked Mar 21 Sabbir Hossain 14.6k points
0 votes
1 answer 11 views
11 views
Problem: Can anyone help? TypeError: Cannot read property 'message' of undefined - Twitter API
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 47 views
47 views
Problem: cannot read property 'symbol(symbol.iterator)' of undefined.
asked Feb 16 charles mathews 5.5k points
0 votes
1 answer 4 views
4 views
Problem: Does anyone know what this error is or why my minified react bundle would throw this error?
asked May 3 salim1 60.6k points
0 votes
1 answer 8 views
8 views
Problem: any ideas on what i need to do for this problem? cannot read property 'render' of undefined
asked Apr 15 Rohit kr 17.5k points