npm install --force从源无法下载包(ETARGET或E451),也没有自动新建node_modules文件夹,如何通过手动新建文件夹和下载指定无法下载的包来解决问题

诸神缄默不语-个人技术博文与视频目录

具体的场景是我拿到的是一个现成的前端项目,通过我们公司自己搭建的镜像来配置环境。更换镜像源的代码是:npm config set registry private_mirror_url
顺便如果想用淘宝的镜像的话可以把URL写成这个:https://registry.npmmirror.com/

我使用内网镜像会报这个报错信息,意思是这个包我们镜像没有:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for @onlyoffice/document-editor-vue@^1.4.0.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user_name\AppData\Local\npm-cache\_logs\2025-04-27omit-debug-0.log

如果用淘宝镜像则会报这个报错信息,意思是那个镜像觉得这个包有风险,所以直接给ban了:

npm ERR! code E451
npm ERR! 451 Unavailable For Legal Reasons - GET https://registry.npmmirror.com/chalk-next - [UNAVAILABLE_FOR_LEGAL_REASONS] chalk-next was blocked, reason: vabjs bad guy, steal env and delete files. (operator: cnpmcore_admin/omit)

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user_name\AppData\Local\npm-cache\_logs\2025-04-27omit-debug-0.log

↑顺便这个chalk-next真的是个有风险的包,被投毒了,会自动删除代码文件,请看:npm 包 chalk-next 被开发者投毒,源码 SRC 目录被删除一、事件简述 1月5日,有开发者在 twitte - 掘金 【开源之耻】vue-admin-beautiful npm 包投毒事件始末 – 码中人的博客
也许你会好奇那我为什么还非要下这个包呢?因为我得先把项目跑起来才能知道接下来能怎么办……

总之造成的后果都是一样的,就是没有办法下载特定包,也没有自动新建node_modules文件夹。解决方式是从已经下好特定包的电脑直接把node_modules里的特定包文件夹转移到新电脑上,人工新建一个node_modules文件夹放进去。
然后再重新运行npm install --force就能把包下到node_modules文件夹里了,也会自动跳过已经下载好的包文件!

本文撰写过程中参考的网络资料:

  1. npm、yarn、pnpm 最新国内镜像源设置和常见问题解决_npm 镜像-优快云博客
C:\Users\15990\Desktop\diangoRecomemend\project\static\home>npm install npm warn old lockfile npm warn old lockfile The package-lock.json file was created with an old version of npm, npm warn old lockfile so supplemental metadata must be fetched from the registry. npm warn old lockfile npm warn old lockfile This is a one-time fix-up, please be patient... npm warn old lockfile npm warn old lockfile Could not fetch metadata for vue-loader-v16@16.3.1 vue-loader-v16: No matching version found for vue-loader-v16@16.3.1. npm warn old lockfile at module.exports (E:\nodejs\node_modules\npm\node_modules\npm-pick-manifest\lib\index.js:215:23) npm warn old lockfile at RegistryFetcher.manifest (E:\nodejs\node_modules\npm\node_modules\pacote\lib\registry.js:130:54) npm warn old lockfile at async E:\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:715:24 { npm warn old lockfile code: 'ETARGET', npm warn old lockfile type: 'version', npm warn old lockfile wanted: '16.3.1', npm warn old lockfile versions: [ npm warn old lockfile '16.0.0-beta.5', npm warn old lockfile '16.0.0-beta.5.1', npm warn old lockfile '16.0.0-beta.5.2', npm warn old lockfile '16.0.0-beta.5.3', npm warn old lockfile '16.0.0-beta.5.4' npm warn old lockfile ], npm warn old lockfile distTags: { latest: '16.0.0-beta.5.4' }, npm warn old lockfile defaultTag: 'latest' npm warn old lockfile } npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency tree npm error npm error While resolving: client_home@0.1.0 npm error Found: vue@3.5.16 npm error node_modules/vue npm error vue@"^3.2.40" from the root project npm error npm error Could not resolve dependency: npm error peer vue@"^2.5.17" from element-ui@2.15.14 npm error node_modules/element-ui npm error element-ui@"^2.15.0" from the root project npm error npm error Fix the upstream dependency conflict, or retry npm error this command with --force or --legacy-peer-deps npm error to accept an incorrect (and potentially broken) dependency resolution. npm error npm error npm error For a full report see: npm error C:\Users\15990\AppData\Local\npm-cache\_logs\2025-06-14T13_58_07_877Z-eresolve-report.txt npm error A complete log of this run can be found in: C:\Users\15990\AppData\Local\npm-cache\_logs\2025-06-14T13_58_07_877Z-debug-0.log
06-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

诸神缄默不语

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值