节点错误无法读取未定义的属性“解析" [英] Node error Cannot read property 'resolve' of undefined
问题描述
我正在使用 reactjs,但无法使用 npm install
安装任何软件包.我收到的错误消息是:
I am using reactjs and am unable to install any packages using npm install
. The error message I'm getting is :
npm ERR! Cannot read property 'resolve' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! /home/stash/.npm/_logs/2019-03-11T10_07_30_264Z-debug.log
当我执行 npm install -verbose
时:
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'install',
npm verb cli '-verbose' ]
npm info using npm@6.7.0
npm info using node@v11.10.1
npm verb npm-session 869376d36eca27b5
npm info lifecycle proj-lite@1.0.0-alpha.6~preinstall: proj-lite@1.0.0-alpha.6
npm timing stage:loadCurrentTree Completed in 22ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1231ms
npm timing stage:rollbackFailedOptional Completed in 1ms
npm timing stage:runTopLevelLifecycles Completed in 2661ms
npm verb stack TypeError: Cannot read property 'resolve' of undefined
npm verb stack at regFetch (/usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js:76:23)
npm verb stack at fetchPackument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:42:10)
npm verb stack at packument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:20:10)
npm verb stack at getManifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:22:10)
npm verb stack at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:13:10)
npm verb stack at Object.manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/index.js:17:12)
npm verb stack at Object.Fetcher#manifest [as manifest] (/usr/local/lib/node_modules/npm/node_modules/genfun/lib/genfun.js:15:38)
npm verb stack at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetch.js:23:18)
npm verb stack at pinflight (/usr/local/lib/node_modules/npm/node_modules/pacote/manifest.js:24:12)
npm verb stack at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:29:24
npm verb stack at Promise._execute (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/debuggability.js:313:9)
npm verb stack at Promise._resolveFromExecutor (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:483:18)
npm verb stack at new Promise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:79:10)
npm verb stack at _inflight (/usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:28:25)
npm verb stack at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:22:14
npm verb stack at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm verb cwd /var/www/html/lite-proj/lite-proj
npm verb Linux 4.4.0-142-generic
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-verbose"
npm verb node v11.10.1
npm verb npm v6.7.0
npm ERR! Cannot read property 'resolve' of undefined
npm verb exit [ 1, true ]
npm timing npm Completed in 3862ms
npm ERR! A complete log of this run can be found in:
npm ERR! /home/stash/.npm/_logs/2019-03-11T10_12_15_921Z-debug.log
我什至无法卸载 npm 并重新安装它,因为我在尝试卸载时遇到了同样的错误.这里有什么问题,我该如何解决?
I am not even able to uninstall npm and reinstall it as I am getting the same error when I try to uninstall. What is the issue here and how do I fix it?
推荐答案
错误的原因可能是全局包和节点版本冲突.我卸载了 node 和 npm,然后重新安装了它们.
The reason for the error was probably conflicting global packages and node versions. I uninstalled node and npm and then reinstalled them.
删除 nodejs 和相关的包(如 npm):
To remove nodejs and associated packages (like npm):
sudo apt-get purge --auto-remove nodejs
Nodejs 和 npm 会在系统中留下文件,这可能会在重新安装过程中导致问题.我也不得不删除它们.
Nodejs and npm will leave files in the system which may cause issues during reinstallation. I had to remove them as well.
虽然手动删除包是一种不好的做法(这可能会导致包管理器出现问题),但它对我的情况有所帮助.此答案显示了如何手动删除 nodejs 和相关文件.
Although it is a bad practice to remove packages manually (it may cause problems with the package manager), it helped my case. This answer shows how to remove nodejs and related files manually.
重新安装它们:
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
这篇关于节点错误无法读取未定义的属性“解析"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!