React Native项目执行postinstall脚本报错:rn-nodeify未被识别
解决React Native postinstall脚本报错问题
问题原因
Windows终端(CMD/PowerShell)不识别类Unix系统里的./相对路径写法,导致执行./node_modules/.bin/rn-nodeify时触发'.' is not recognized as an internal or external command错误。
修复方案
修改package.json中的postinstall脚本,换成Windows兼容的写法:
方法1:直接调用命令(推荐)
npm/yarn会自动从node_modules/.bin目录查找可执行命令,无需写完整路径:
"scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint .", "postinstall": "rn-nodeify --hack --install" }
方法2:使用Windows格式路径
如果方法1不生效,换成Windows的反斜杠路径写法:
"scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint .", "postinstall": ".\\node_modules\\.bin\\rn-nodeify --hack --install" }
验证步骤
- 保存修改后的
package.json - 删除
node_modules文件夹和package-lock.json(或yarn.lock) - 重新执行
npm install(或yarn install) - 再次尝试运行项目
内容的提问来源于stack exchange,提问作者Kunal Kalwar
相关产品推荐
相关产品推荐

