[英]Why can't I modify module.exports? Why does my browser complain after no problems from `npm run build`?
為什么瀏覽器不讓我做:
獲取者.js
let Getters = {}
Getters.foo = function(){ return 1; }
Getters.bar = function(){ return 2; }
module.exports = Getters;
但是在npm run build
和serve -s build -l 4000
,我收到錯誤消息:
Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
at Module.<anonymous> (Getters.js:954)
有沒有簡單的方法來解決這個問題?
您是否使用 es6 import 語句導入了任何模塊? 如果是,請嘗試更新到常見的 js 模塊。 不要混淆 es6 和 commonJS 導入語句。
es6
import a from '/a.js';
commonJS
const a = require('/a.js');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.