运行 pod install 后找不到模块 node_modules/@react-native-community/cli/build/bin.js

Ds.*_*109 2 cocoapods react-native

从一个新项目(npx react-native init MyTestApp)开始,当我运行 npm list @react-native-community/cli 时,我得到:

MyTestApp@4.1.0 /Users/user/Desktop/Projects/MyTestApp
??? (empty)
Run Code Online (Sandbox Code Playgroud)

更大的问题是我无法运行 pod install,我得到:

    throw err;
    ^

Error: Cannot find module '/MyTestApp/node_modules/@react-native-community/cli/build/bin.js
Run Code Online (Sandbox Code Playgroud)

但是,我在 node_modules 中看到 @react-native-community/cli/build/bin.js

作为参考,package.json:

{
  "name": "MyTestApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/cli": "^4.6.0",
    "react": "16.11.0",
    "react-native": "0.62.1"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.58.0",
    "react-test-renderer": "16.11.0"
  },
  "jest": {
    "preset": "react-native"
  }
}
Run Code Online (Sandbox Code Playgroud)

我有一个要升级的现有项目,但出现相同的错误。这就是我决定尝试一个新项目的原因。但是,我在新项目中也遇到了同样的错误。

pod version = 1.9.1 node version = v8.3.0 npm version = 5.2.0

nec*_*ixy 9

我在节点模块中看到文件时遇到了同样的问题,但仍然给我同样的错误。

This might sound crazy as it does to me but for some reason I get this error only when I run pod install from the VS Code Terminal but when I run this same from MacOS terminal it worked fine and pod were installed.

It may not work for you but worth giving a shot while it worked for me. :)

  • @Nostromo 确保你没有在 vscode 中自动附加调试器 (3认同)

小智 7

正如Kieran在另一条评论中提到的,如果您使用 VSCode,请确保禁用 VSCode 调试器的自动附加功能。

cmd + shift + p-> Debug: toggle auto attach->disable

我的问题就这样解决了。

另外,pod install在普通终端中尝试在 vscode 之外应该也可以工作。