【问题标题】:While running ReactiNative project index.js not found error occur运行 ReactiNative 项目 index.js 时出现未找到错误
【发布时间】:2019-03-29 05:29:59
【问题描述】:

我是 ReactNative 的新手,我面临一个问题。请检查以下日志是否相同。我在尝试使用

运行 ReactNative 项目时遇到了这个问题
react-native run-android

错误日志:

错误:无法从D:\ReactNativeProject\testing\node_modules\react-native\scripts/. 解析模块./index:无法从D:\ReactNativeProject\testing\node_modules\react-native\scripts/. 找到模块./index。事实上,这些文件都不存在: * D:\ReactNativeProject\testing\node_modules\react-native\scripts\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx) * D:\ReactNativeProject\testing\node_modules\react-native\scripts\index\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx) 在 ModuleResolver.resolveDependency (D:\ReactNativeProject\testing\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15) 在 ResolutionRequest.resolveDependency (D:\ReactNativeProject\testing\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18) 在 DependencyGraph.resolveDependency (D:\ReactNativeProject\testing\node_modules\metro\src\node-haste\DependencyGraph.js:283:16) 在 D:\ReactNativeProject\testing\node_modules\metro\src\lib\transformHelpers.js:261:42 在服务器。 (D:\ReactNativeProject\testing\node_modules\metro\src\Server.js:1038:41) 在 Generator.next () 在 asyncGeneratorStep (D:\ReactNativeProject\testing\node_modules\metro\src\Server.js:99:24) 在 _next (D:\ReactNativeProject\testing\node_modules\metro\src\Server.js:119:9) ::ffff:127.0.0.1 - - [29/Mar/2019:05:12:54 +0000] "GET /index.delta?platform=android&dev=true&minify=false HTTP/1.1" 500 - "-" "okhttp/ 3.12.1"

我做了什么来解决这个问题?

1)。当我在 Github 上找到解决方案时,我尝试了以下命令

react-native start --reset-cache

2)。我尝试删除 node-module 文件夹并重新安装,但仍然没有成功。

React Native 版本: 0.59.2

【问题讨论】:

    标签: node.js reactjs react-native node-modules


    【解决方案1】:

    转到node_modules\react-native\scripts\launchPackager.bat

    // 注释这一行

    node "%~dp0..\cli.js" start 
    

    添加这一行

    node "%~dp0..\cli.js" start --projectRoot ../../../
    

    然后运行您的项目根cd android && gradlew clean 并在运行react-native run-android 之后

    【讨论】:

    • 谢谢兄弟,它有效。你节省了我的时间。我花了很多时间在这上面。你能告诉我为什么我们做出这些改变吗?
    • @LokeshDesai 我在这个版本 0.59.2 中遇到了这个问题。请查看此链接以查看未决问题github.com/facebook/react-native/issues/23908
    • 是的,我在 0.59.2 中也遇到了问题。感谢您的链接。大多数人能够使用 react-native start --reset-cache 解决这个问题,但就我而言,它现在正在工作。无论如何感谢您的解决方案。
    【解决方案2】:

    运行

    react-native start -- --reset-cache
    

    然后运行

    react-native run-android

    在单独的命令行窗口中。

    这对我来说很好。

    我还注意到人们通过在 node_modules\react-native\scripts\launchPackager.bat 中编写一些代码来修复它,但不建议在 node_modules 中编写代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 2020-11-16
      • 2018-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多