【问题标题】:Problem starting a react-native app in simulator在模拟器中启动 react-native 应用程序的问题
【发布时间】:2019-06-27 01:44:02
【问题描述】:

这是我的 package.json

{
  "name": "Locals",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@babel/runtime": "^7.3.1",
    "react": "16.6.3",
    "react-native": "0.58.3",
    "react-native-elements": "^1.0.0",
    "react-native-vector-icons": "^6.2.0"
  },
  "devDependencies": {
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "24.0.0",
    "jest": "24.0.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

我得到以下失败日志:

加载依赖图,完成。错误:捆绑失败:错误:不能 查找模块“NativeModules” 在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15) 在 Function.Module._load (internal/modules/cjs/loader.js:507:25) 在 Module.require (internal/modules/cjs/loader.js:637:17) 在需要(内部/模块/cjs/helpers.js:20:18) 在 Object.get NativeModules [as NativeModules] (/Users/vb05mj/Developer/personal/small-town/Locals/node_modules/react-native/Libraries/react-native/react-native-implementation.js:313:12) 在 Object.get [as NativeModules] (/Users/vb05mj/Developer/personal/small-town/Locals/node_modules/react-native-vector-icons/dist/lib/react-native.js:1:344) 在对象。 (/Users/vb05mj/Developer/personal/small-town/Locals/node_modules/react-native-vector-icons/dist/lib/ensure-native-module-available.js:1:238) 在 Module._compile (internal/modules/cjs/loader.js:689:30)

【问题讨论】:

  • 您必须将版本保存在 package.json 中。您是否运行了 npm install react-native-vector-icons --save ,然后将其作为本机依赖项与 react-native link react-native-vector-icons 链接
  • 是的,没有帮助。
  • 好吧,问题似乎出在 react-native-vector-icons 上。我的下一步是react-native unlink react-native-vector-icons && npm remove react-native-vector-icons 并尝试重新安装(确保我使用了npm install react-native-vector-icons --savereact-native link react-native-vector-icons

标签: reactjs react-native


【解决方案1】:

运行rm -rf node_modules && npm install 重新安装依赖项。

确保react-native-vector-icons 已正确链接。通常你应该在android/app/build.gradle 中有这一行:

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

更多信息在这里: https://github.com/oblador/react-native-vector-icons#android

杀死 npm 服务器(ctrl+c 或只运行 kill -15 [pid])并使用 npm start -- --reset-cache 重新启动它

最后,别忘了重新构建您的应用: ./android/gradlew clean && react-native run-android

【讨论】:

    猜你喜欢
    • 2019-08-07
    • 2019-12-23
    • 2021-12-29
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    相关资源
    最近更新 更多