uniapp 复制项目后加载不出来,总是报错 “default” is not exported by
发布:HelloJq 时间:2025-05-15
如果根据报错去更新每个文件就陷入误区了
Error when using sourcemap for reporting an error: Can’t resolve original location of error.
main.js (7:7): “default” is not exported by “xxx/polyfill/polyfill.js”, imported by “../../../../xxx/main.js”.
16:53:26.309 at main.js:7:7
16:53:26.309 at main.js:7:7
16:53:26.309 5:
16:53:26.309 6: // Api函数polyfill(目前为实验版本,如不需要,可删除!)’;
16:53:26.309 7: import Polyfill from ‘./polyfill/polyfill’;
16:53:26.309 ^
16:53:26.309 8: Polyfill.init();
CommonJS 语法(module.exports),使用了 ES 模块语法(import … from),导致报错
方法:
混合导出
const Polyfill = {
init,
guid
};
// CommonJS 导出
module.exports = Polyfill;
// ES Module 兼容导出
export default Polyfill;
解决方案: