我正在使用 webpack 开发一个网站。当我有这样的代码时:
import $ from 'jquery';
function foo() {};
module.exports = foo;
我收到错误 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
.
结果是改变 import $ from 'jquery'
至 var $ = require('jquery')
不要造成任何错误。
为什么使用 module.exports 导入会导致此错误?改用 require 有什么问题吗?
最佳答案
您不能混合使用 import
和 module.exports
。在 import
世界中,您需要导出内容。
// Change this
module.exports = foo;
// To this
export default foo;
关于javascript - webpack:同一模块中的 import + module.exports 导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42449999/