React Native:找不到模块@ react-native-community-cli

时间:2019-09-10 05:23:12

标签: react-native

在我不得不重新安装计算机上的所有内容之前,项目运行正常。我先运行npm install然后运行expo start

,会收到以下错误
internal/modules/cjs/loader.js:296
      throw err;
      ^

Error: Cannot find module '/home/amber/Documents/GitKraken/school-notification-1/App/node_modules/@react-native-community/cli/build/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:288:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:515:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:759:27)
    at Function.Module._load (internal/modules/cjs/loader.js:677:27)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (/home/amber/Documents/GitKraken/school-notification-1/App/node_modules/react-native/local-cli/cli.js:12:11)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32) {
  code: 'MODULE_NOT_FOUND',
  path: '/home/amber/Documents/GitKraken/school-notification-1/App/node_modules/@react-native-community/cli/package.json',
  requestPath: '@react-native-community/cli'
}

Metro Bundler process exited with code 1

这是我的package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^10.0.3",
    "@react-navigation/web": "^1.0.0-alpha.9",
    "axios": "^0.19.0",
    "expo": "^34.0.1",
    "expo-asset": "^6.0.0",
    "expo-constants": "^6.0.0",
    "expo-font": "~6.0.0",
    "expo-web-browser": "6.0.0",
    "navigationbar-react-native": "0.0.5",
    "qs": "^6.8.0",
    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz",
    "react-native-action-button": "^2.8.5",
    "react-native-anchor-carousel": "^3.1.1",
    "react-native-app-intro-slider": "^3.0.0",
    "react-native-calendars": "^1.210.0",
    "react-native-circle-drawer": "^1.0.0",
    "react-native-drawer-menu": "^0.2.5",
    "react-native-elements": "^1.1.0",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-global-props": "^1.1.5",
    "react-native-htmlview": "^0.15.0",
    "react-native-loading-spinner-overlay": "^1.0.1",
    "react-native-popup-dialog": "^0.18.3",
    "react-native-side-drawer": "^1.1.11",
    "react-native-side-menu": "^1.1.3",
    "react-native-sidebar": "^0.3.0",
    "react-native-web": "^0.11.4",
    "react-navigation": "^3.11.0"
  },
  "devDependencies": {
    "babel-preset-expo": "^6.0.0",
    "jest-expo": "^34.0.0"
  },
  "private": true
}

5 个答案:

答案 0 :(得分:6)

安装此软件包。

npm i @react-native-community/cli

答案 1 :(得分:2)

使用npm install @ react-native-community-cli并再次运行,否则删除package-lock.json和node_modules,再次安装npm,请在运行项目之前先进行清理

答案 2 :(得分:1)

删除了package-lock.jsonnode_modules,然后重新运行npm install,现在可以正常使用了。

答案 3 :(得分:0)

尝试删除 node_modules/ 然后运行 ​​npm install

答案 4 :(得分:0)

免责声明:可能偏离主题,与 AppCenter 问题相关

如果您在 App Center 构建中遇到错误 Error: Cannot find module '/node_modules/react-native/local-cli/cli.js',那么您需要:

  1. 从您的 @react-native-community/cli 中删除 package.json
  2. 删除package-lock.json并运行npm i(或rm -rf yarn-lock.json && yarn
  3. 将更改推送到分支并运行 App Center 构建

希望它会帮助某人,因为我没有找到解决该问题的任何方法