node打包报错:ERROR in xxxx.js Module not found: Error: Can’t resolve xxxx in ‘xxx’ error Command failed with exit code 1.

原文链接:node打包报错:ERROR in xxxx.js Module not found: Error: Can’t resolve xxxx in ‘xxx’ error Command failed with exit code 1. – 每天进步一点点 (longkui.site)

 

0.背景

anguar项目。分为主包和子包,子包推送到npm私有仓库中,然后主包在packjson中引入子包的版本号,把主包打包。

打包过程中,开始报错:

ERROR in ./node_modules/xxxx/fesm5/xxxxxxx.js
Module not found: Error: Can’t resolve ‘app/routes/xxxxx/xxxx/xxx.component’ in ‘D:\xxx\xxx\xx\xxx\xx-\node_modules\xxxx\fesm5’

这个报错的意思是没有正常引用子包。

根本原因是子包引用不对,比如下面这样的引用:

import { xxxxComponent } from ‘app/routes/xxxxx/xxx/xxxx.component’;

我们需要把上面这样的引用改成下面这样:

import { xxxxComponent } from ‘../../routes/xxxxx/xxx/xxxx.component’;

重新打包,发布到npm仓库,然后主包重新引用子包就可以了。

posted on   longkui  阅读(72)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示