setup_env.sh 的 react-native 启动 EACCESS 错误

react-native start EACCESS error for setup_env.sh

所以,我在 ReactNative 中的第一个项目从 Windows 到 运行 Android OS。在 Mac 上结帐,以相同的方式配置它,当我尝试使用 react-native start 启动反应包管理器时,出现以下错误:

child_process.js:506
    throw err;
    ^
Error: spawnSync /Users/UserName/Desktop/Path/node_modules/react-native/local-cli/setup_env.sh EACCES
    at exports._errnoException (util.js:1022:11)
    at spawnSync (child_process.js:461:20)
    at Object.execFileSync (child_process.js:498:13)
    at Object.run (/Users/UserName/Desktop/Path/node_modules/react-native/local-cli/cliEntry.js:156:16)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:117:7)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

我知道它只尝试将 ulimit(打开文件限制)设置为 2048,这对于非 root 用户是允许的。还尝试 运行 使用 sudo 赋予它 root 权限的命令。 运行 ulimit -a 机器上的打开文件限制为 256,我尝试将默认值 2048 更改为此。尝试将其增加到 4096 以及完全删除该命令。似乎没有任何区别,错误仍然存​​在。

使用 react-native init DemoProject 创建了一个新项目,打包程序似乎在该文件夹中启动,所以问题出在其他地方?

我的package.json是:

{
  "name": "React Native",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "native-base": "^0.5.18",
    "react": "15.4.1",
    "react-addons-shallow-compare": "^15.4.1",
    "react-native": "0.39.2",
    "react-native-drawer": "^2.3.0",
    "react-native-icons": "^0.7.1",
    "react-native-loading-spinner-overlay": "^0.4.1",
    "react-native-md-textinput": "^2.0.4",
    "react-native-overlay": "^0.5.0",
    "react-native-scrollable-tab-view": "^0.7.0",
    "react-native-tab-view": "0.0.40",
    "react-redux": "^4.4.6",
    "react-timer-mixin": "^0.13.3",
    "redux": "^3.6.0"
  },
  "devDependencies": {
    "babel-jest": "17.0.2",
    "babel-preset-react-native": "1.9.0",
    "jest": "17.0.3",
    "react-test-renderer": "15.4.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

此外,如果重要的话,我在全球范围内安装了 sinopia、browserify 和 yarn。

首先,我不确定是否应该在 Mac 上再次通过 npm 添加所有本地依赖项,然后只复制我的代码,否则应该没问题,但还有其他问题。

如果我能在不重新添加依赖项的情况下解决这个问题就好了。提前致谢。

只需转到我的基础项目目录,然后 运行

chmod -R 777 node_modules

这是 npm 的 bug。在他们修复错误之前,您有 2 种方法来修复问题:

  1. 将 npm 版本降级到 5.3.0
  2. npm i react-native 之后,运行 chmod -R 775 node_modules

在我的例子中,当我执行 react-native link:

时,错误出在一个特定的文件上
Error: spawnSync ~/native-starter-kit/node_modules/react-native/local-cli/setup_env.sh EACCES

所以我通过 运行 修复了它:chmod +x 在那个文件上。

正如杰里指出的那样,这是 NPM 中的一个错误。现在有可用的修复程序。您可以使用 npm i -g npm.

更新 NPM

我更新到版本 5.4.2 (npm --version),使用 npm remove --save react-native 删除了 React Native,并使用 npm i --save react-native 重新安装了 RN。这解决了我的问题。

(作为替代方案,您可能想尝试使用 yarn 而不是 npm。)

我遇到了同样的问题,我试过了,最初的问题已经解决了

chmod -R 775 android