Windows 7, npm install -g react-native-cli gives “Cannot read property 'path' of null”

≡放荡痞女 提交于 2019-12-24 06:08:14

问题


I am Beginning the getting started react native tutorial by following the official docs from here https://facebook.github.io/react-native/docs/getting-started.html

  1. Finished installing choco, nodejs and python without any trouble
  2. While doing npm install -g react-native-cli i get "Cannot read property 'path' of null" (full error below)

npm install -g react-native-cli

C:\Windows\system32>npm install -g react-native-cli
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "react-native-cli"
npm ERR! node v7.6.0
npm ERR! npm  v4.1.2

npm ERR! Cannot read property 'path' of null
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Windows\system32\npm-debug.log

C:\Windows\system32>

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   'install',
1 verbose cli   '-g',
1 verbose cli   'react-native-cli' ]
2 info using npm@4.1.2
3 info using node@v7.6.0
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData react-native-cli
8 silly fetchNamedPackageData react-native-cli
9 silly mapToRegistry name react-native-cli
10 silly mapToRegistry using default registry
11 silly mapToRegistry registry http://localhost:4873/
12 silly mapToRegistry data Result {
12 silly mapToRegistry   raw: 'react-native-cli',
12 silly mapToRegistry   scope: null,
12 silly mapToRegistry   escapedName: 'react-native-cli',
12 silly mapToRegistry   name: 'react-native-cli',
12 silly mapToRegistry   rawSpec: '',
12 silly mapToRegistry   spec: 'latest',
12 silly mapToRegistry   type: 'tag' }
13 silly mapToRegistry uri http://localhost:4873/react-native-cli
14 verbose request uri http://localhost:4873/react-native-cli
15 verbose request no auth needed
16 info attempt registry request try #1 at 4:37:49 PM
17 verbose request using bearer token for auth
18 verbose request id 91c9343245cf6325
19 http request GET http://localhost:4873/react-native-cli
20 info retry will retry, error on last attempt: Error: connect ECONNREFUSED 127.0.0.1:4873
21 info attempt registry request try #2 at 4:38:00 PM
22 verbose request using bearer token for auth
23 http request GET http://localhost:4873/react-native-cli
24 info retry will retry, error on last attempt: Error: connect ECONNREFUSED 127.0.0.1:4873
25 info attempt registry request try #3 at 4:39:01 PM
26 verbose request using bearer token for auth
27 http request GET http://localhost:4873/react-native-cli
28 silly fetchPackageMetaData Error: connect ECONNREFUSED 127.0.0.1:4873
28 silly fetchPackageMetaData     at Object.exports._errnoException (util.js:1028:11)
28 silly fetchPackageMetaData     at exports._exceptionWithHostPort (util.js:1051:20)
28 silly fetchPackageMetaData     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
28 silly fetchPackageMetaData  error for react-native-cli { Error: connect ECONNREFUSED 127.0.0.1:4873
28 silly fetchPackageMetaData     at Object.exports._errnoException (util.js:1028:11)
28 silly fetchPackageMetaData     at exports._exceptionWithHostPort (util.js:1051:20)
28 silly fetchPackageMetaData     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
28 silly fetchPackageMetaData   code: 'ECONNREFUSED',
28 silly fetchPackageMetaData   errno: 'ECONNREFUSED',
28 silly fetchPackageMetaData   syscall: 'connect',
28 silly fetchPackageMetaData   address: '127.0.0.1',
28 silly fetchPackageMetaData   port: 4873 }
29 silly rollbackFailedOptional Starting
30 verbose stack TypeError: Cannot read property 'path' of null
30 verbose stack     at Installer.rollbackFailedOptional (C:\Program Files\nodejs\node_modules\npm\lib\install.js:511:29)
30 verbose stack     at Array.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
30 verbose stack     at LOOP (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
30 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:18:7
30 verbose stack     at C:\Program Files\nodejs\node_modules\npm\lib\install.js:337:5
30 verbose stack     at Array.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
30 verbose stack     at LOOP (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
30 verbose stack     at chain (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:20:5)
30 verbose stack     at C:\Program Files\nodejs\node_modules\npm\lib\install.js:294:5
30 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:16:22
31 verbose cwd C:\Windows\system32
32 error Windows_NT 6.1.7601
33 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "react-native-cli"
34 error node v7.6.0
35 error npm  v4.1.2
36 error Cannot read property 'path' of null
37 error If you need help, you may report this error at:
37 error     <https://github.com/npm/npm/issues>
38 verbose exit [ 1, true ]

This is what i tried,

  1. Checked the permission of the folder "C:\Program Files\nodejs\node_modules" and found that its readonly
  2. Transfered ownership and assigned full control to myself and administrator user, and then removed read only via attrib -r -s C:\Program Files\nodejs\node_modules /S /D
  3. When i checked the permission of the folder it was still read only but all the files inside is not under the control of read only
  4. Execute the "npm install react-native-cli" command again which resulted in the same error

Solution

  1. If you had used Sinopia earlier and created a .npmrc file then rename or delete the config file
  2. Use the npm install -g react-native-cli to install the lib successfully

Reasoning

  1. Sinopia config file will make npm to look for packages in the local machine first and if it is not found, then goes to fetch the package at npmjs.com
  2. I had earlier installed and used Sinopia and uninstalled it later, but looks like the config file was not removed 3.So the config file made npm look for packages in the local machine, whereas the local server was not at all running in the first place to say the package was not available !

回答1:


I think you're using a proxy, is "http://localhost:4873/" you proxy(or you set a custom registry)? If it is, you had better check your network, and make sure your can use npm to install others module normally.

"Error: connect ECONNREFUSED 127.0.0.1:4873" shows that it can not connect to 127.0.0.1:4873




回答2:


I think your npm path is not set in environment variables. Please set your npm path or run this command from where your npm is installed. To set your environment variable in windows 1. Go to properties in My Computer. 2. Go to advanced system settings. 3. Then go to Environment Variables. 4. Then add npm path in the PATH variable. For e.g. C:\Users\myuser\AppData\Roaming\npm;



来源:https://stackoverflow.com/questions/42390323/windows-7-npm-install-g-react-native-cli-gives-cannot-read-property-path-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!