Windows 7中,npm安装-g react-native-cli给出“无法读取属性path”的空“

我正在从这里https://facebook.github.io/react-native/docs/getting-started.html官方文档开始反应原生教程

  1. 完成安装choco,nodejs和python没有任何麻烦
  2. 当做npm安装-g react-native-cli我得到“不能读取属性'path的空值”(下面的完整错误)

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 ] 

这是我试过的,

  1. 检查文件夹“C:\ Program Files \ nodejs \ node_modules”的权限并发现其只读
  2. 转移所有权并将完全控制权分配给自己和pipe理员用户,然后通过attrib -r -s C:\ Program Files \ nodejs \ node_modules / S / D
  3. 当我检查文件夹的权限,它仍然只读,但里面的所有文件不受只读的控制
  4. 再次执行导致相同错误的“npm install react-native-cli”命令

  1. 如果你之前使用过Sinopia并创build了一个.npmrc文件,那么重命名或者删除这个configuration文件
  2. 使用npm install -g react-native-cli成功安装lib

推理

  1. Sinopia的configuration文件会使npm先在本地机器上寻找软件包,如果没有find,那么就去npmjs.com取得软件包
  2. 我以前安装和使用了Sinopia并在以后卸载了它,但是看起来configuration文件没有被删除。因此,configuration文件使得npm在本地机器上寻找软件包,而本地服务器根本不在运行说包不可用!

Solutions Collecting From Web of "Windows 7中,npm安装-g react-native-cli给出“无法读取属性path”的空“"

我想你使用的代理,是“ http:// localhost:4873 / ”你代理(或者你设置一个自定义注册表)? 如果是的话,最好检查一下你的网络,确认你的npm可以正常安装其他模块。

“错误:连接ECONNREFUSED 127.0.0.1:4873”显示它无法连接到127.0.0.1:4873

我认为你的npm路径没有在环境变量中设置。 请设置您的npm路径,或从您的npm安装位置运行此命令。 在Windows中设置环境变量1.转到“我的电脑”中的属性。 2.转到高级系统设置。 3.然后去环境变量。 4.然后在PATH变量中添加npm路径。 例如C:\ Users \ myuser \ AppData \ Roaming \ npm;