我正在使用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世界上,您需要导出东西。