【问题标题】:Error: Unable to resolve module `./index` from `\node_modules\react-native\scripts/.`错误:无法从 `\node_modules\react-native\scripts/.` 解析模块 `./index`
【发布时间】:2019-03-13 19:15:47
【问题描述】:

升级我的 react native 时出现此错误。

上面写着

错误:无法解析模块 ./index 来自 \node_modules\react-native\scripts/.:模块./index 不能 可以从\node_modules\react-native\scripts/. 找到。确实,没有一个 这些文件存在:

其实不知道怎么解决。任何人都可以帮忙吗?谢谢

我目前使用的版本

“反应”:“^16.8.4”, “反应原生”:“^0.59.0”,

【问题讨论】:

标签: reactjs react-native


【解决方案1】:

This linked solved my problem.

虽然你每次开始一个新项目时都需要这样做..这是 react-native 的升级问题

更新 node_modules\react-native\scripts\launchPackager.bat 文件。 @echo 关闭 标题 Metro Bundler 调用 .packager.bat

// delete this line
node "%~dp0..\cli.js" start 

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

pause
exit

我们在这里给出 Metro 实例的项目根路径,

或者在 \node_modules@react-native-community\cli\build\commands\runAndroid\runAndroid.js 编辑这个, 常量 procConfig = {

    // delete this line    
    cwd: scriptsDir

    // add this line
    cwd: process.cwd()
};

【讨论】:

  • 在我的情况下,我在升级后注意到它,在我的 react-native 中......在我的 runAdriod.js 文件中使用 cwd:process.cwd()
【解决方案2】:

尝试从node_modules 中删除所有内容,然后执行npm install

cd node_modules
rm -rf *

cd ../
npm install 

【讨论】:

  • 感谢您的回复。我已经清除了缓存但没有运气。
【解决方案3】:

这是 react-native 版本最新升级的问题。请降级你的电流它会工作。我也试过了

【讨论】:

    【解决方案4】:

    我也面临同样的问题。我刚刚更新到 0.59.1,这不起作用... 作为一种解决方法,我在单独的选项卡中运行 Metro Builder,然后在单独的选项卡中运行 react。

    react-native start --reset-cache 在一个终端中并保持打开状态 react-native run-android 在另一个终端中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 2020-05-19
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2023-02-16
      相关资源
      最近更新 更多