Npm无法安装任何软件包。

14

我需要帮助,因为我无法安装任何npm软件包。当我尝试安装一些东西时,我会收到这个错误。

在此输入图像描述

我的node版本是6.11.0,npm版本是3.10.10。

npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'server:dev',
1 verbose cli   '--',
1 verbose cli   '--hot',
1 verbose cli   '--proxy-requests' ]
2 info using npm@3.10.10
3 info using node@v6.11.0
4 verbose stack Error: missing script: server:dev
4 verbose stack     at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:151:19)
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:61:5
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:356:5
4 verbose stack     at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:320:45)
4 verbose stack     at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:354:3)
4 verbose stack     at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:124:5)
4 verbose stack     at ReadFileContext.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:295:20)
4 verbose stack     at ReadFileContext.callback (C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16)
4 verbose stack     at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:366:13)
5 verbose cwd C:\Users\Scyli\Desktop\angular
6 error Windows_NT 10.0.14393
7 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "server:dev" "--" "--hot" "--proxy-requests"
8 error node v6.11.0
9 error npm  v3.10.10
10 error missing script: server:dev
11 error If you need help, you may report this error at:
11 error     <https://github.com/npm/npm/issues>
12 verbose exit [ 1, true ]

请帮我解决这个问题。

9个回答

6

我尝试了很多不同的建议以找到解决方案。仅供参考:我正在使用Goorm在线IDE。

最终,只需在根目录下重新安装npm即可解决问题。我运行了以下命令:

sudo npm install npm -g

之后,我又可以像往常一样安装软件包了。


6
解决方法:32位的NodeJs完全解决了我的问题。

感谢您的存在。 - Lorenzo Von Matterhorn

5
这些命令解决了相同的问题。
npm install -g npm
npm cache clean
npm update
npm install

2

编辑npm-config文件后,我的问题得到了解决。

要编辑该文件,请使用npm config edit命令。

这是我的npm配置文件。

;;;;
; npm userconfig file
; this is a simple ini-formatted file
; lines that start with semi-colons are comments.
; read `npm help config` for help on the various options
;;;;


;;;;
; all options with default values
;;;;
; access=null

; allow-same-version=false

; always-auth=false

; also=null

; auth-type=legacy

; bin-links=true

; browser=null

; ca=null

; cafile=undefined

; cache=C:\Users\Admin\AppData\Roaming\npm-cache

; cache-lock-stale=60000

; cache-lock-retries=10

; cache-lock-wait=10000

; cache-max=null

; cache-min=10

; cert=null

; cidr=null

; color=true

; depth=null

; description=true

; dev=false

; dry-run=false

; editor=notepad.exe

; engine-strict=false

; force=false

; fetch-retries=2

; fetch-retry-factor=10

; fetch-retry-mintimeout=10000

; fetch-retry-maxtimeout=60000

; git=git

; git-tag-version=true

; commit-hooks=true

; global=false

; globalconfig=C:\Users\Admin\AppData\Roaming\npm\etc\npmrc

; global-style=false

; group=0

; ham-it-up=false

; heading=npm

; if-present=false

; ignore-prepublish=false

; ignore-scripts=false

; init-module=C:\Users\Admin\.npm-init.js

; init-author-name=

; init-author-email=

; init-author-url=

; init-version=1.0.0

; init-license=ISC

; json=false

; key=null

; legacy-bundling=false

; link=false

; local-address=undefined

; loglevel=notice

; logs-max=10

; long=false

; maxsockets=50

; message=%s

; metrics-registry=null

; node-options=null

; node-version=8.11.2

; offline=false

; onload-script=null

; only=null

; optional=true

; otp=0

; package-lock=true

; package-lock-only=false

; parseable=false

; prefer-offline=false

; prefer-online=false

; prefix=C:\Program Files\nodejs

; production=false

; progress=true

; proxy=null

; https-proxy=null

; user-agent=npm/{npm-version} node/{node-version} {platform} {arch}

; read-only=false

; rebuild-bundle=true

; registry=https://registry.npmjs.org/

; rollback=true

; save=true

; save-bundle=false

; save-dev=false

; save-exact=false

; save-optional=false

; save-prefix=^

; save-prod=false

; scope=

; script-shell=null

; scripts-prepend-node-path=warn-only

; searchopts=

; searchexclude=null

; searchlimit=20

; searchstaleness=900

; send-metrics=false

; shell=C:\Windows\system32\cmd.exe

; shrinkwrap=true

; sign-git-tag=false

; sso-poll-frequency=500

; sso-type=oauth

; strict-ssl=true

; tag=latest

; tag-version-prefix=v

; timing=false

; tmp=C:\Users\Admin\AppData\Local\Temp

; unicode=false

; unsafe-perm=true

; usage=false

; user=0

; userconfig=C:\Users\Admin\.npmrc

; umask=0

; version=false

; versions=false

; viewer=browser

; _exit=true

; globalignorefile=C:\Users\Admin\AppData\Roaming\npm\etc\npmignore

1
我遇到了叶子签名错误,解决方法如下: //首先输入以下内容
npm config set strict-ssl false

//然后

npm config set NODE_TLS_REJECT_UNAUTHORIZED 0

并在此之后尝试安装包。

0

我猜您需要清除缓存并从 nodejs 安装文件夹的根目录更新 npm。

为此,请导航至您的 C:\Program Files\nodejs\npm 目录并发出以下命令:

npm cache clean

然后使用以下命令更新您的npm,

npm update

希望这能帮到你!


@DócziSzilárd,不要使用cmder,请尝试在CMD中使用以下命令(开始=>(输入)CMD=>右键单击显示的“CMD”条目,然后单击以管理员身份运行)。 - David R
也许这也是一样的问题。也许代理设置有问题?我使用Wi-Fi,但在其他论坛中读到,代理设置可能会出现一些问题。 - Dóczi Szilárd
有时甚至防病毒程序也会引起这些错误。如果您有这些程序,请尝试暂时禁用它们。 - David R
你能否关闭Windows Defender,然后尝试执行命令? - David R
1
已解决,我必须安装32位的nodeJs,尽管我使用的是64位的Windows。 - Dóczi Szilárd
显示剩余3条评论

0
在我的情况下,我正在克隆一个其他开发人员在工作中使用和构建没有问题的GIT存储库。尝试了所有这些解决方案,但最终的解决方法是将我的npm版本降级到早期版本。非常简单,我知道,但如果您的输出与团队中的其他开发人员不同,这行代码可能会为您节省一天的调试时间!
npm -v

0
很多答案都是对的或接近正确,但至少在某些用例中错过了要点。如果您正在使用包管理器提供的默认版本,则必须将其删除并安装 NodeSource 仓库 或 Node 版本管理器等其他版本。这是我在 RockyLinux 8 上遇到的情况。
curl -sL https://rpm.nodesource.com/setup_18.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
rm -f nodesource_setup.sh

sudo dnf remove nodejs npm -y
sudo dnf install nodejs -y

然后确认:

node -v
npm -v

-1
如果您是Windows用户,请以管理员身份运行cmd,然后安装软件包。在使用npm安装express时,这对我很有效。

还有其他解决方案吗?您可以提出没有缺点的建议吗? - Namasivaayam L

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接