npm报错

本文汇总了使用npm和yarn过程中遇到的各种错误及其解决方案,包括404 Not Found、无法加载脚本、网络连接问题等,并提供了详细的排查与修复步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、问题:404 Not Found - GET https://registry.npmjs.org/** - Not found

二、问题:yarn : 无法加载文件 C:\Users\**\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本。

三、问题:error An unexpected error occurred: "http://npm.company.com/**/-/**-3.26.17.tgz: unexpected end of file".

四、yarn dev:cross-env CODE_ENV=local cooking watch -p 'cooking' 不是内部或外部命令,也不是可运行的程序或批处理文件。

五、npm ERR! xxx@0.1.0 dev: `cross-env CODE_ENV=dev vue-cli-service build`

六、Error: EPERM: operation not permitted, lstat ''


记录使用npm时各类报错

一、问题:404 Not Found - GET https://registry.npmjs.org/** - Not found

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/**-core - Not found        
npm ERR! 404
npm ERR! 404  '**-core@1.7.7' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR!     C:\Users\***\AppData\Roaming\npm-cache\_logs\2021-07-26T03_12_06_731Z-debug.log

解决方案: 

 1、查看一下是否设置代理:

npm config set proxy
npm config get https-proxy

2、以上两个命令如果返回null,那么就不需要执行以下命令清理

npm config set https-proxy null
npm config get proxy null

3、重新设置:

npm config set registry https://registry.npmjs.org/

若无效,则尝试:

npm config set registry https://skimdb.npmjs.com/registry

或者如果不起作用,请尝试 GitHub 链接:

npm config set registry https://github.com/npm/npm-registry-couchapp

二、问题:yarn : 无法加载文件 C:\Users\**\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本。

yarn : 无法加载文件 C:\Users\**\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行 
脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Executi 
on_Policies。
所在位置 行:1 字符: 1
+ yarn dev
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

解决方案: 

1、搜索cmd,以管理员方式运行powershell
2、使用命令更改计算机的执行策略:set-ExecutionPolicy RemoteSigned

PS C:\windows\system32> set-ExecutionPolicy RemoteSigned

执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y] 是(Y)  [A] 全是(A)  [N] 否(N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“N”): y

3、查看当前执行策略:

PS C:\windows\system32> get-ExecutionPolicy
RemoteSigned

三、问题:error An unexpected error occurred: "http://npm.company.com/**/-/**-3.26.17.tgz: unexpected end of file".

error An unexpected error occurred: "http://npm.company.com/**/-/**-3.26.17.tgz: unexpected end of file".
info If you think this is a bug, please open a bug report with the information provided in "D:\\code\\**\\**\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
info There appears to be trouble with your network connection. Retrying...

解决方案:

配置公司镜像源

nrm add **

如果执行报错,参考 nrm 安装完成但 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value);_a806488840的博客-优快云博客

四、yarn dev:cross-env CODE_ENV=local cooking watch -p 'cooking' 不是内部或外部命令,也不是可运行的程序或批处理文件。

PS D:\code\**\**-Frontend> yarn dev 
yarn run v1.22.10
$ cross-env CODE_ENV=local cooking watch -p
'cooking' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

尝试解决:

npm install -g cooking
npm install -g cooking-cli

后又报错:

$ cross-env CODE_ENV=local cooking watch -p

[cooking@1.5.4] - chalk.yellow('permission denied')
    Try running with sudo  or get access

    sudo chown -R $USER:$(id -gn $USER) C:\Users\**\.cooking


error Command failed with exit code 1.

解决方案:

原node版本为14.17.3,切换为12.22.1就不报错了……

nvm use 12.22.1

五、npm ERR! xxx@0.1.0 dev: `cross-env CODE_ENV=dev vue-cli-service build`

npm run dev报错:

ERROR  Build failed with errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! quality-measure@1.0.98 deploy_dev: `cross-env CODE_ENV=dev vue-cli-service build && ymm_upload -r ./dist -n qualityMeasure -t dev -z 0 -f 1`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the quality-measure@1.0.98 deploy_dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /data/jenkins/.npm/_logs/2022-02-28T06_35_38_029Z-debug.log

解决方案:

package.json中vuevue-template-compiler版本不一致导致,重新下一个同版本包就可以了

"vue": "^2.5.21",
"vue-template-compiler": "^2.5.21"


六、Error: EPERM: operation not permitted, lstat ''

npm install报错:
 
error code EPERM
error syscall lstat
error path D:\code\snake\amh-mindmap-editor\node_modules\.staging\echarts-1f2fabae\dist\echarts.common.min.js
error errno -4048
error Error: EPERM: operation not permitted, lstat 'D:\code\snake\amh-mindmap-editor\node_modules\.staging\echarts-1f2fabae\dist\echarts.common.min.js'
error  { [Error: EPERM: operation not permitted, lstat 'D:\code\snake\amh-mindmap-editor\node_modules\.staging\echarts-1f2fabae\dist\echarts.common.min.js']
error   cause:
error    { Error: EPERM: operation not permitted, lstat 'D:\code\snake\amh-mindmap-editor\node_modules\.staging\echarts-1f2fabae\dist\echarts.common.min.js'
error      errno: -4048,
error      code: 'EPERM',
error      syscall: 'lstat',
error      path:
error       'D:\\code\\snake\\amh-mindmap-editor\\node_modules\\.staging\\echarts-1f2fabae\\dist\\echarts.common.min.js' },
error   stack:
error    'Error: EPERM: operation not permitted, lstat \'D:\\code\\snake\\amh-mindmap-editor\\node_modules\\.staging\\echarts-1f2fabae\\dist\\echarts.common.min.js\'',
error   errno: -4048,
error   code: 'EPERM',
error   syscall: 'lstat',
error   path:
error    'D:\\code\\snake\\amh-mindmap-editor\\node_modules\\.staging\\echarts-1f2fabae\\dist\\echarts.common.min.js',
error   parent: 'amh-mindmap-editor' }
error The operation was rejected by your operating system.
error It's possible that the file was already in use (by a text editor or antivirus),
error or that you lack permissions to access it.
error
error If you believe this might be a permissions issue, please double-check the
error permissions of the file and its containing directories, or try running
error the command again as root/Administrator.
verbose exit [ -4048, true ]

解决方案:npm install安装失败,报错记录之The operation was rejected by your operating system.
尝试方法二、三后出现四报错

npm install 日志

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> uws@9.14.0 install D:\code\snake\amh-mindmap-editor\node_modules\uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0


> node-sass@4.14.1 install D:\code\snake\amh-mindmap-editor\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-64_binding.node": 

read ECONNRESET

Hint: If github.com is not accessible in your location
      try setting a proxy via HTTP_PROXY, e.g.

      export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

      npm config set proxy http://example.com:8080

> phantomjs-prebuilt@2.1.16 install D:\code\snake\amh-mindmap-editor\node_modules\phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip
Saving to C:\Users\TONG~1.SHE\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip
Receiving...

Error making request.
Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27)

sass版本问题,注意不能直接npm i node-sass,一定要重新设置一个源,不然还是报错。

npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass 
npm i node-sass

持续更新……

<think>好的,用户之前遇到了使用nvm安装Node.js 14.17.0失败的问题,现在给出了新的错误信息:“error installing 14.17.0: open C:\Users\77571\AppData\Local\Temp\nvm-npm-264190328\npm-v6.14.13.zip: The system cannot find the file specified.”。首先,我需要分析这个错误的原因。 错误信息指出系统找不到指定的npm压缩包文件。这可能是因为在下载过程中npm包没有正确下载,或者在解压时路径出现问题。用户之前已经尝试过网络检查和镜像源更换,但问题依然存在,特别是在Windows环境下,权限问题或者临时文件夹的访问限制也可能是原因。 首先,考虑到用户使用的是Windows系统,需要检查临时文件夹的权限。用户可能没有足够的权限访问或写入AppData\Local\Temp目录,或者防病毒软件/安全软件阻止了文件的创建。这时候需要建议用户检查临时文件夹权限,并暂时关闭安全软件进行测试。 其次,可能npm包下载不完整或损坏。用户之前可能更换了镜像源,但需要确认是否正确设置。可能需要手动指定npm的镜像源,或者清除nvm的缓存,强制重新下载所有文件。 另外,Windows系统下路径长度限制也可能导致问题,特别是当路径过长时,系统无法处理。需要建议用户缩短路径或启用长路径支持。 最后,如果所有方法都无效,可能需要手动下载npm包并放置到指定位置,或者考虑使用其他安装方式,比如直接下载Node.js安装包。 总结起来,可能的解决步骤包括:检查临时文件夹权限、关闭安全软件、清除缓存并指定镜像源、手动下载npm包、启用长路径支持。需要一步步引导用户尝试这些方法,并根据结果调整后续步骤。</think>根据您提供的错误信息,主要问题集中在 **npm压缩包文件无法被正确访问**。以下是针对Windows系统的分步解决方案: --- ### 🔍 问题核心原因分析 错误 `open ... npm-v6.14.13.zip: The system cannot find the file specified` 表明: 1. **临时文件路径访问权限不足** 2. **防病毒软件/Windows Defender拦截了文件操作** 3. **npm镜像源文件未正确下载** --- ### 🛠️ 分步解决方案 #### 步骤1:手动清理临时文件 ```powershell # 强制删除残留文件 Remove-Item -Recurse -Force $env:LOCALAPPDATA\Temp\nvm-* ``` #### 步骤2:以管理员权限运行PowerShell - 右键点击PowerShell图标 → 选择 **"以管理员身份运行"** - 重新执行安装命令: ```powershell nvm install 14.17.0 ``` #### 步骤3:禁用防病毒软件临时防护(关键步骤) - 暂时关闭 **Windows Defender实时保护**: 1. 打开 `Windows安全中心` 2. 进入 `病毒和威胁防护` → `管理设置` 3. 关闭 `实时保护` - 关闭第三方杀毒软件(如360安全卫士、腾讯电脑管家等) #### 步骤4:强制指定npm镜像源 ```powershell # 设置Node.jsnpm双镜像源 $env:NVM_NODEJS_ORG_MIRROR="https://npmmirror.com/mirrors/node" $env:NVM_NPM_REGISTRY="https://registry.npmmirror.com" # 强制重新安装 nvm uninstall 14.17.0 nvm install 14.17.0 ``` #### 步骤5:手动补全缺失文件(终极方案) 1. 直接下载npm压缩包: ```powershell # 下载地址需与nvm日志中的路径一致 Invoke-WebRequest -Uri "https://npmmirror.com/mirrors/npm/6.14.13/npm-6.14.13.zip" -OutFile "$env:LOCALAPPDATA\Temp\nvm-npm-264190328\npm-v6.14.13.zip" ``` 2. 重新运行安装命令: ```powershell nvm install 14.17.0 ``` --- ### ⚠️ Windows特有注意事项 | 问题类型 | 解决方案 | |-------------------------|--------------------------------------------------------------------------| | 长路径限制 | 在组策略中启用 `启用Win32长路径` (Windows 10 1803+) | | 用户目录权限问题 | 执行 `icacls "%LOCALAPPDATA%\Temp" /grant Users:(OI)(CI)F` 赋予完全控制权 | | 系统残留文件冲突 | 使用 `Everything` 工具搜索 `nvm-npm-*` 并手动删除 | --- ### ✅ 验证安装成功 ```powershell nvm use 14.17.0 node -v # 应输出 v14.17.0 npm -v # 应输出 6.14.13 ``` 如果问题仍未解决,请提供完整的安装日志(可通过 `nvm install 14.17.0 2>&1 | tee install.log` 生成日志文件),以便进一步诊断。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值