[Solved] Vue:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#

problem found

Run a previous Vue+webpack vue imitation news website small project, report an error

Because I didn’t study Vue deeply, I always reported this error, and it took a long time (to be exact a whole afternoon ^…^) to find the reason -v-

Uncaught TypeError: Cannot assign to read only property ‘ exports ‘ of object ‘ #<Object> ‘

Click on the wrong file and mark the wrong place as a piece of code:

1 import {normalTime} from  ' ./timeFormat ' ;
 2 module.exports = {
 3    normalTime
 4 };

Is  module.exports;


Search with Google, and various searches on forums:

The reasons are as follows:

The code above is ok. You can mix require and export. You can’t mix import and module.exports.

The translation means that there is nothing wrong with the code. When webpack is packaged, you can mix require and export in the js file. But import and module.exports cannot be mixed

Because import and module.exports are not allowed to be mixed in webpack 2  ,

The solution is to change it to ES6.

1 import {normalTime} from  ' ./timeFormat ' ;
 2 export default normalTime;

Run again:


to sum up

The above is the whole content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message and exchange. Thank you for your support to Script Home.

Similar Posts: