开发者问题收集

npm install 返回“TypeError:无法将未定义或空转换为对象”

2016-12-13
20953

我正在尝试使用 npm install -g eslint 全局安装 eslint。这是使用 nvm 安装的 [email protected] / [email protected] 的新版本。我收到的错误是:

Stacktrace:

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 [email protected]
3 info using [email protected]
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 ]
3个回答

问题是我有一个旧的 .npmrc,它使用 skimdb.npmjs.org 指向 npm 注册表。我删除了该文件,现在我的模块安装正常。

我可以通过输入 npm config list registry 来检查注册表,它现在指向我认为是默认的: https://registry.npmjs.org/

YPCrumble
2016-12-17

很奇怪,但我刚刚将 npm 从 8.5.2 降级到 6.14.16,一切开始正常工作。

Asiri Piyajanaka
2022-04-06

这主要是因为网络连接速度太差

或 npm 版本较旧

对于网络连接问题,请尝试以下操作

您可以尝试以下操作使其正常工作

npm install --prefer-offline --no-audit

其次,您可以添加项目 .npmrc 文件并添加以下行

fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000

您也可以尝试 npm config set timeout 6000000

对于较旧的 npm 相关问题,请尝试以下操作

npm install -g [email protected]  

如果您不知道 npm 的版本,请使用以下命令列出

npm view npm versions

您可能还需要更新节点版本,以使用以下命令更新节点nvm

nvm use 10    

然后尝试 npm install

如果仍然出错,请尝试使用 yarn 而不是 npm。

vikram eklare
2023-08-30