• Register
1 vote

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
5,680 points

Related questions

0 votes
1 answer 40 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 6 views
Problem: cannot read property 'symbol(symbol.iterator)' of undefined.
asked Feb 16 charles mathews 3.8k points
0 votes
1 answer 687 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
0 votes
1 answer 139 views
Problem: I am naive to Angular, Webpack, Bootstrap and typescript. I have tried to write a service but it is throwing the below error while my app is bootstrapping. I am currently using ng2 2.4.2 and the angular-cli 1.0.0-beta.24. My TypeError as below: &ldquo;Uncaught typeerror: ... .navigate(['/project', query]); } public extractData(res: Response) { let body = res.json(); return body || {}; } }
asked Sep 3, 2020 Raphael Pacheco 4.9k points
0 votes
0 answers 54 views
TypeError: Router.use() requires a middleware function but got a Object at Function.use (E:\firebase-CRUD_api\functions\node_modules\express\lib\router\index.js:458:13) at Function.<anonymous> (E:\firebase-CRUD_api\functions\node_modules\express\lib\application.js:220:21) ... at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Module.require (internal/modules/cjs/loader.js:1042:19)
asked May 17, 2020 anonymous
1 vote
2 answers 758 views
Problem : I am very new to the Node.js and I am having few issues. I am using the Node.js 4.10 and Express 2.4.3. While trying to execute my code I am receiving below error : Error: Can't render headers after they are sent to the client. ... , scope: 'offline_access,email,user_about_me,user_activities,manage_pages,publish_stream', failedUri: '/noauth' }) ])); realapp.use(realapp.router); }); . . .
asked Dec 12, 2019 alecxe 7.5k points
0 votes
1 answer 125 views
0 votes
1 answer 2.9K views
Problem : I am just starting coding using the nodejs with express. So I simply did this in my file test.js which is into my folder routes : const myexpress = require('express'); const myrouter = new myexpress.Router(); myrouter.get('/test', (req, res) => { res.send(` ... browser, it tells me it Cannot get/test I don't understand why this is happening to me. Please let me know how can I fix this?
asked Jan 23, 2020 jwilliam 3.9k points
0 votes
0 answers 4 views
Problem: web process failed to bind to $port within 60 seconds of launch.
asked 5 days ago charles mathews 3.8k points
0 votes
1 answer 6 views
Problem: module build failed: error: cannot find module 'node-sass'
asked Feb 18 charles mathews 3.8k points