React Native 错误“无法解析模块‘react-native’”

阿鲁门农

我正在尝试学习,React Native所以我继续并按照官方文档站点上入门指南中的所有步骤进行操作我有一些经验,React所以我想扩展它。

大约 6 个月前,我确实涉足了一个简单的“hello world”应用程序,并且在 Android 模拟器和 IoS 模拟器上一切正常。也在我的设备上进行了测试,没有任何问题。由于我忙于其他工作,我直到现在才回过头来。

尝试react-native run-android命令时出现的错误

    Metro Bundler ready.

Loading dependency graph, done.
error: bundling failed: Error: Unable to resolve module `react-native` from `/Users/arunmenon/Sites/reactnative/website/index.js`: Module `react-native` does not exist in the Haste module map or in these directories:
  /Users/arunmenon/Sites/reactnative/website/node_modules

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
    at ModuleResolver.resolveDependency (/Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:161:1460)
    at ResolutionRequest.resolveDependency (/Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:91:16)
    at DependencyGraph.resolveDependency (/Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)
    at dependencies.map.relativePath (/Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)
    at /Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33
    at Generator.next (<anonymous>)
    at step (/Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)
    at /Users/arunmenon/Sites/reactnative/website/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473
 BUNDLE  [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.

我尝试了所有建议的步骤,但问题仍然存在。错误:

Error: Unable to resolve module `react-native` from `/Users/arunmenon/Sites/reactnative/website/index.js`: 
Module `react-native` does not exist in the Haste module map or in these directories:
  /Users/arunmenon/Sites/reactnative/website/node_modules

表明从node_modules. index.js 中的第一行import { AppRegistry } from 'react-native';就是抛出错误的地方。

提到的路径是有效的,我确实在路径的 node_modules 目录中安装了 react-native。

我正在 Mac 上开发,目前目标设备是 Android。我要走react-nativeCLI 命令路线,而不是create-react-native-app路线。

我有 Android Studio 3.1.3(昨晚更新)、Node 8.11.2、NPM 6.1.0、Watchman 4.9.0(通过 Homebrew 安装)、Java JDK 1.8.0_144。

我按照入门指南找到了 T。因为我更早开始工作 - 大约 6 个月前 - 我想知道为什么我现在得到这个。我有与那时相同的 Android Studio 版本(我昨天更新了 Android Studio 以排除旧版本的问题。新版本也出现相同的错误)当时和现在的区别:

  • React-native 库版本显然是从那时开始提升的
  • Java 版本,我最近更新到最新
  • Node 和 NPM 版本较新
  • 守望者我也认为自从 Homebrew 确实更新了它

其他一切都是一样的。我也尝试了几个全新安装 - 从头开始​​,即但它没有用。

我的 package.json:

{
  "name": "website",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.3.1",
    "react-native": "0.55.4"
  },
  "devDependencies": {
    "babel-jest": "23.2.0",
    "babel-preset-react-native": "4.0.0",
    "jest": "23.2.0",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}
沙.....

请从“%appdata%\Temp”中删除所有 react-native 特定文件夹,然后尝试以下命令:

cd android
gradlew clean
cd.. 并删除 node_modules 文件夹
npm cache clean --force
npm install
npm start -- --reset-cache
react-native run-android

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

React Native:包解析错误

来自分类Dev

Twilio React Native-无法解析模块密码

来自分类Dev

错误:找不到模块“ react-native-web” /未找到模块:错误:无法解析模块“ react-native-web”

来自分类Dev

React Native:无法解析模块fs

来自分类Dev

无法要求以本机解析。'需要未知的模块“ react-native”

来自分类Dev

无法解析模块“ react-native-reanimated”

来自分类Dev

react-native无法解析模块'warnOnce'

来自分类Dev

无法从App.js解析(模块)-React Native

来自分类Dev

错误:未定义无法在React Native中从'AppNavigator.js'解析模块'./Home'

来自分类Dev

JSON解析错误:无法识别的令牌“ <”-React Native

来自分类Dev

收到此错误:错误:捆绑失败:错误:无法解析模块“ react-native-safe-area-context”

来自分类Dev

找不到模块:错误:无法解析“ ../aws-exports”(React-Native Expo Web)

来自分类Dev

React Native导入错误:无法使用.bin解析模块(如何导入某种类型的文件?)

来自分类Dev

React Native-使用我制作的自定义组件时出现错误(错误:undefined无法解析模块<MyModule>)

来自分类Dev

React-Native错误:无法从“ index.js”解析模块“ / screen / Welcome”:

来自分类Dev

无法从App.js解析模块-React Native

来自分类Dev

react-native-community / CheckBox无法解析模块

来自分类Dev

尝试在React Native中组织模块时无法解析模块

来自分类Dev

React Native错误-无法解析模块`。/ tab-bar-item-ios`

来自分类Dev

React Native无法解析模块

来自分类Dev

React Native Android模块

来自分类Dev

UnableToResolveError:无法解析模块`./node_modules/react-native/packager/src/components` React Native

来自分类Dev

React-native 无法在导入 js 文件时解析模块

来自分类Dev

图像路径 react-native:无法解析模块

来自分类Dev

React Native - 返回响应错误代码:500 - 无法解析模块。这可能与错误 react-native/issues/4968 有关

来自分类Dev

AsyncStorage - 错误(React Native)

来自分类Dev

React Native Image 无法解析模块

来自分类Dev

React Native 错误:无法解析模块`./index`

来自分类Dev

React Native TypeScript:无法解析模块(但它存在)

Related 相关文章

  1. 1

    React Native:包解析错误

  2. 2

    Twilio React Native-无法解析模块密码

  3. 3

    错误:找不到模块“ react-native-web” /未找到模块:错误:无法解析模块“ react-native-web”

  4. 4

    React Native:无法解析模块fs

  5. 5

    无法要求以本机解析。'需要未知的模块“ react-native”

  6. 6

    无法解析模块“ react-native-reanimated”

  7. 7

    react-native无法解析模块'warnOnce'

  8. 8

    无法从App.js解析(模块)-React Native

  9. 9

    错误:未定义无法在React Native中从'AppNavigator.js'解析模块'./Home'

  10. 10

    JSON解析错误:无法识别的令牌“ <”-React Native

  11. 11

    收到此错误:错误:捆绑失败:错误:无法解析模块“ react-native-safe-area-context”

  12. 12

    找不到模块:错误:无法解析“ ../aws-exports”(React-Native Expo Web)

  13. 13

    React Native导入错误:无法使用.bin解析模块(如何导入某种类型的文件?)

  14. 14

    React Native-使用我制作的自定义组件时出现错误(错误:undefined无法解析模块<MyModule>)

  15. 15

    React-Native错误:无法从“ index.js”解析模块“ / screen / Welcome”:

  16. 16

    无法从App.js解析模块-React Native

  17. 17

    react-native-community / CheckBox无法解析模块

  18. 18

    尝试在React Native中组织模块时无法解析模块

  19. 19

    React Native错误-无法解析模块`。/ tab-bar-item-ios`

  20. 20

    React Native无法解析模块

  21. 21

    React Native Android模块

  22. 22

    UnableToResolveError:无法解析模块`./node_modules/react-native/packager/src/components` React Native

  23. 23

    React-native 无法在导入 js 文件时解析模块

  24. 24

    图像路径 react-native:无法解析模块

  25. 25

    React Native - 返回响应错误代码:500 - 无法解析模块。这可能与错误 react-native/issues/4968 有关

  26. 26

    AsyncStorage - 错误(React Native)

  27. 27

    React Native Image 无法解析模块

  28. 28

    React Native 错误:无法解析模块`./index`

  29. 29

    React Native TypeScript:无法解析模块(但它存在)

热门标签

归档