


















在本地环境打包正常,但在Jenkins环境构建时遇到了与SWR库相关的模块导入错误。错误信息显示无法从非ECMAScript模块中导入命名导出,只能使用默认导出。主要报错如下:
Can't import the named export 'createContext' from non EcmaScript module (only default export is available) Can't import the named export 'createElement' from non EcmaScript module (only default export is available) Can't import the named export 'useCallback' from non EcmaScript module (only default export is available) // ... 更多类似错误
这个问题主要是由于:
将SWR版本降级到1.3.0版本,这个版本使用了更兼容的模块系统。在package.json中添加:
{
"dependencies": {
"swr": "1.3.0"
}
}
为了确保所有依赖包使用相同版本的SWR,在package.json中添加resolutions配置:
{
"resolutions": {
"swr": "1.3.0"
}
}
完成配置修改后,需要:
如果问题仍然存在,可以检查:1. Jenkins环境中的Node.js版本是否与本地开发环境一致
这个问题主要是由于模块系统的兼容性导致的,通过降级SWR版本并确保依赖版本一致性可以解决。这个案例也提醒我们在使用新版本库时要注意模块系统的兼容性问题,特别是在不同环境下的构建过程中。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。