当前位置: 首页 > 工具软件 > npm-consider > 使用案例 >

ReacNative之Command `npm install --save --save-exact react-native` failed.

何高歌
2023-12-01
Error: EACCES: permission denied, mkdir '/Users/liuzhao/.npm/_npx/2938'
TypeError: Cannot read property 'loaded' of undefined
    at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
    at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:77:20
    at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)
    at /usr/local/lib/node_modules/npm/lib/npm.js:263:24
    at /usr/local/lib/node_modules/npm/lib/config/core.js:83:7
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/npm/lib/config/core.js:82:13
    at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
    at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:173:20)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
    at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
    at process.emit (events.js:203:13)
    at process._fatalException (internal/process/execution.js:150:25)
安装 [ 'create-LZShopping@latest' ] 失败,错误代码:7
liuzhaodeMacBook-Pro:RNDemo liuzhao$ react-native init LZShoppingCentre
This will walk you through creating a new React Native project in /Users/liuzhao/Documents/liuzhao/RNDemo/LZShoppingCentre
Installing react-native...
Consider installing yarn to make this faster: https://yarnpkg.com
npm ERR! path /Users/liuzhao/.npm/_cacache/index-v5/81/5f
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/Users/liuzhao/.npm/_cacache/index-v5/81/5f'
npm ERR!  [OperationalError: EACCES: permission denied, mkdir '/Users/liuzhao/.npm/_cacache/index-v5/81/5f'] {
npm ERR!   cause: [Error: EACCES: permission denied, mkdir '/Users/liuzhao/.npm/_cacache/index-v5/81/5f'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'mkdir',
npm ERR!     path: '/Users/liuzhao/.npm/_cacache/index-v5/81/5f'
npm ERR!   },
npm ERR!   isOperational: true,
npm ERR!   stack: "Error: EACCES: permission denied, mkdir '/Users/liuzhao/.npm/_cacache/index-v5/81/5f'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/Users/liuzhao/.npm/_cacache/index-v5/81/5f',
npm ERR!   parent: 'react-native'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/liuzhao/.npm/_logs/2019-07-31T13_47_41_187Z-debug.log
Error: Command failed: npm install --save --save-exact react-native
    at checkExecSyncError (child_process.js:621:11)
    at execSync (child_process.js:657:15)
    at run (/usr/local/lib/node_modules/react-native-cli/index.js:294:5)
    at createProject (/usr/local/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/usr/local/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (internal/modules/cjs/loader.js:777:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12) {
  status: 243,
  signal: null,
  output: [ null, null, null ],
  pid: 3290,
  stdout: null,
  stderr: null
}
Command `npm install --save --save-exact react-native` failed.

 

解决办法:

1. 删除/usr/local/lib中的所有node和node_modules
2. 删除/usr/local/lib中的所有node和node_modules的文件夹
3. 如果是从brew安装的, 运行brew uninstall node
4. 检查~/中所有的local, lib或者include文件夹, 删除里面所有node和node_modules
5. 在/usr/local/bin中, 删除所有node的可执行文件
6. 最后运行以下代码:

sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
估计是你的node.js
$ brew update
$ brew uninstall node
$ brew install node
 类似资料: