admin管理员组文章数量:1323703
Uncaught Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ./assets/js/jquery/interview.js
I get this error when I try to export a function with module.exports and when I import it inside another file. I tried to use export default but the JS file that calls the original file can't find any method. I also found this topic but I don't have a babel.config.json file...
Here is my code :
Interview.prototype = function ($) {
const collapseLocalStoredElements = function (localStorageId) {
let collapseItemsIds = localStorage.getItem(localStorageId);
console.log(collapseItemsIds)
}
return {
collapseLocalStoredElements: collapseLocalStoredElements,
};
}(jQuery);
// export default Interview;
module.exports = Interview;
App.js
//Import
let InterviewImport = require ('./js/jquery/interview');
//Uses
let Interview = new InterviewImport();
console.log(Interview.collapseLocalStoredElements('collapseItemsIds'));
Thanks!!
Uncaught Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ./assets/js/jquery/interview.js
I get this error when I try to export a function with module.exports and when I import it inside another file. I tried to use export default but the JS file that calls the original file can't find any method. I also found this topic https://github./babel/babel/issues/12731 but I don't have a babel.config.json file...
Here is my code :
Interview.prototype = function ($) {
const collapseLocalStoredElements = function (localStorageId) {
let collapseItemsIds = localStorage.getItem(localStorageId);
console.log(collapseItemsIds)
}
return {
collapseLocalStoredElements: collapseLocalStoredElements,
};
}(jQuery);
// export default Interview;
module.exports = Interview;
App.js
//Import
let InterviewImport = require ('./js/jquery/interview');
//Uses
let Interview = new InterviewImport();
console.log(Interview.collapseLocalStoredElements('collapseItemsIds'));
Thanks!!
Share Improve this question edited Oct 21, 2022 at 9:51 MrsStorm asked Oct 21, 2022 at 9:25 MrsStormMrsStorm 551 gold badge1 silver badge6 bronze badges2 Answers
Reset to default 2Try using ESM syntax.
export default Interview;
App.js
Import Interview from ('./js/jquery/interview');
There also seem to be one too many closing brackets in your code, I've removed the one that I think was unnecessary. The function also seems to be self-executing. You might want to remove that.
Interview.prototype = function (localStorageId) {
let collapseItemsIds = localStorage.getItem(localStorageId);
console.log(collapseItemsIds);
};
Happened to me because I was importing something as ES module and exporting everything in CommonJS style in the same file.
本文标签:
版权声明:本文标题:javascript - ES Modules may not assign module.exports or exports.*, Use ESM export syntax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742131243a2422169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论