npm install返回“TypeError:无法将undefined或null转换为对象”

8fsztsew  于 2023-04-06  发布在  其他
关注(0)|答案(5)|浏览(287)

我尝试使用npm install -g eslint全局安装eslint。这是使用nvm安装的node@7.2.1/npm@3.10.10的新版本。我得到的错误是:
堆栈跟踪:

0 info it worked if it ends with ok
1 verbose cli [ '/Users/fitvalet/.nvm/versions/node/v7.2.1/bin/node',
1 verbose cli   '/Users/fitvalet/.nvm/versions/node/v7.2.1/bin/npm',
1 verbose cli   'install',
1 verbose cli   '-g',
1 verbose cli   'eslint' ]
2 info using npm@3.10.10
3 info using node@v7.2.1
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData eslint
8 silly fetchNamedPackageData eslint
9 silly mapToRegistry name eslint
10 silly mapToRegistry using default registry
11 silly mapToRegistry registry http://skimdb.npmjs.com/registry
12 silly mapToRegistry data Result {
12 silly mapToRegistry   raw: 'eslint',
12 silly mapToRegistry   scope: null,
12 silly mapToRegistry   escapedName: 'eslint',
12 silly mapToRegistry   name: 'eslint',
12 silly mapToRegistry   rawSpec: '',
12 silly mapToRegistry   spec: 'latest',
12 silly mapToRegistry   type: 'tag' }
13 silly mapToRegistry uri http://skimdb.npmjs.com/registry/eslint
14 verbose request uri http://skimdb.npmjs.com/registry/eslint
15 verbose request no auth needed
16 info attempt registry request try #1 at 1:59:17 PM
17 verbose request id 066241c6e4150db4
18 http request GET http://skimdb.npmjs.com/registry/eslint
19 http 200 http://skimdb.npmjs.com/registry/eslint
20 verbose headers { 'cache-control': 'must-revalidate',
20 verbose headers   connection: 'close',
20 verbose headers   'content-type': 'application/json',
20 verbose headers   date: 'Tue, 13 Dec 2016 18:59:17 GMT',
20 verbose headers   server: 'CouchDB/2.0.0 (Erlang OTP/R16B03)',
20 verbose headers   'transfer-encoding': 'chunked',
20 verbose headers   'content-encoding': 'gzip',
20 verbose headers   'strict-transport-security': 'max-age=2592000000; includeSubDomains; preload;' }
21 silly get cb [ 200,
21 silly get   { 'cache-control': 'must-revalidate',
21 silly get     connection: 'close',
21 silly get     'content-type': 'application/json',
21 silly get     date: 'Tue, 13 Dec 2016 18:59:17 GMT',
21 silly get     server: 'CouchDB/2.0.0 (Erlang OTP/R16B03)',
21 silly get     'transfer-encoding': 'chunked',
21 silly get     'content-encoding': 'gzip',
21 silly get     'strict-transport-security': 'max-age=2592000000; includeSubDomains; preload;' } ]
22 verbose get saving undefined to /Users/fitvalet/.npm/skimdb.npmjs.com/registry/eslint/.cache.json
23 verbose correctMkdir /Users/fitvalet/.npm correctMkdir not in flight; initializing
24 verbose makeDirectory /Users/fitvalet/.npm creation not in flight; initializing
25 silly makeDirectory /Users/fitvalet/.npm uid: 501 gid: 20
26 verbose stack TypeError: Cannot convert undefined or null to object
26 verbose stack     at Function.keys (<anonymous>)
26 verbose stack     at pickVersionFromRegistryDocument (/Users/fitvalet/.nvm/versions/node/v7.2.1/lib/node_modules/npm/lib/fetch-package-metadata.js:125:29)
26 verbose stack     at /Users/fitvalet/.nvm/versions/node/v7.2.1/lib/node_modules/npm/node_modules/iferr/index.js:13:50
26 verbose stack     at /Users/fitvalet/.nvm/versions/node/v7.2.1/lib/node_modules/npm/lib/utils/pulse-till-done.js:20:8
26 verbose stack     at saved (/Users/fitvalet/.nvm/versions/node/v7.2.1/lib/node_modules/npm/lib/cache/caching-client.js:174:7)
26 verbose stack     at /Users/fitvalet/.nvm/versions/node/v7.2.1/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:241:18
26 verbose stack     at FSReqWrap.oncomplete (fs.js:111:15)
27 verbose cwd /Users/fitvalet
28 error Darwin 16.1.0
29 error argv "/Users/fitvalet/.nvm/versions/node/v7.2.1/bin/node" "/Users/fitvalet/.nvm/versions/node/v7.2.1/bin/npm" "install" "-g" "eslint"
30 error node v7.2.1
31 error npm  v3.10.10
32 error Cannot convert undefined or null to object
33 error If you need help, you may report this error at:
33 error     <https://github.com/npm/npm/issues>
34 verbose exit [ 1, true ]
ha5z0ras

ha5z0ras1#

问题是我有一个旧的.npmrc,它指向一个使用skimdb.npmjs.org的npm注册表。我删除了这个文件,我的模块现在安装得很好。
我可以通过输入npm config list registry来检查注册表,现在它指向我认为是默认的:https://registry.npmjs.org/

wnavrhmk

wnavrhmk2#

奇怪的是,我刚刚把npm从8.5.2降级到6.14.16,一切都开始工作了。

c9qzyr3d

c9qzyr3d3#

问题是npm注册表运行这个:npm config get registry
并查看它是否设置为所需的URI,默认注册表应设置为https://registry.npmjs.org

dgsult0t

dgsult0t4#

Webstorm可以使用以下conf调试npm cli:

添加npm cli opt --loglevel verbose以显示错误堆栈跟踪详细信息
在WebStorm中,在堆栈跟踪行中设置断点以查找导致此错误原因
在我的例子中,错误是由package.json中的dep引起的

igsr9ssn

igsr9ssn5#

npm install也有同样的问题
我使用npm install --legacy-peer-deps获得了更好的结果
当然,如果你不想要这个选择,这对你来说并不好。

相关问题