简体   繁体   English

无法加载我的 React Native 项目的配置

[英]Failed to load configuration of my react native project

./gradlew clean command in the android directory has issues too. android 目录中的./gradlew clean命令也有问题。 I've tried downgrading the npm version but no help.我试过降级 npm 版本但没有帮助。 Any ideas?有任何想法吗?
Below is the log I get when I run npx react-native run-android :下面是我运行npx react-native run-android时得到的日志:

 error Failed to load configuration of your project.
    Error: Cannot find module '...\node_modules\json-parse-better-errors\index.js'. Please verify that the package.json has a valid "main" entry
        at tryPackage (internal/modules/cjs/loader.js:320:19)
        at Function.Module._findPath (internal/modules/cjs/loader.js:533:18)
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:875:27)
        at Function.Module._load (internal/modules/cjs/loader.js:745:27)
        at Module.require (internal/modules/cjs/loader.js:961:19)
        at require (internal/modules/cjs/helpers.js:92:18)
        at Object.<anonymous> (D:\projects\Beauty\node_modules\parse-json\index.js:3:18)
        at Module._compile (internal/modules/cjs/loader.js:1072:14)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
        at Module.load (internal/modules/cjs/loader.js:937:32)

Environment:环境:

OS: Windows 10操作系统:Windows 10
react native: 0.65.1本机反应:0.65.1
Node: 14.17.4节点:14.17.4
npm: 7.23.0 npm:7.23.0

I got this in an nx monorepo only for a specific app (but not others).我在一个nx monorepo中只为一个特定的应用程序(而不是其他应用程序)得到了这个。 None of the above methods worked for me.以上方法都不适合我。 Finally figured this -终于想通了——

TLDR; TLDR;

  1. This is not the actual error (you probably guessed this).这不是真正的错误(您可能已经猜到了)。 This error message comes from node_modules/@react-native-community/cli/build/index.js OR node_modules/react-native/node_modules/@react-native-community/cli/build/index.js .此错误消息来自node_modules/@react-native-community/cli/build/index.jsnode_modules/react-native/node_modules/@react-native-community/cli/build/index.js

To be sure, you can run this in node_modules directory: find. -name '*.js' -print0 | xargs -0 grep "Failed to load configuration of your project"可以肯定的是,您可以在 node_modules 目录中运行它find. -name '*.js' -print0 | xargs -0 grep "Failed to load configuration of your project" find. -name '*.js' -print0 | xargs -0 grep "Failed to load configuration of your project" find. -name '*.js' -print0 | xargs -0 grep "Failed to load configuration of your project" 2. Edit these files to print the underlying error. find. -name '*.js' -print0 | xargs -0 grep "Failed to load configuration of your project" 2. 编辑这些文件以打印底层错误。

  } catch (error) {
    /**
     * When there is no `package.json` found, the CLI will enter `detached` mode and a subset
     * of commands will be available. That's why we don't throw on such kind of error.
     */
    if (error.message.includes("We couldn't find a package.json")) {
      _cliTools().logger.debug(error.message);

      _cliTools().logger.debug('Failed to load configuration of your project. Only a subset of commands will be available.');
    } else {
      //---> ***** Print the underlying error!
      console.log('=============>', error);
      throw new (_cliTools().CLIError)('Failed to load configuration of your project.', error);
    }
  }
  1. For me, this printed: =============> [CLIError: Node module directory for package react-native-animated-pagination-dots was not found]对我来说,这打印: =============> [CLIError: Node module directory for package react-native-animated-pagination-dots was not found]
  2. All I had to do fix it was yarn add react-native-animated-pagination-dots .我所要做的就是修复它yarn add react-native-animated-pagination-dots If only CLI had printed this underlying error, it would have saved me several hours: :-/如果只有 CLI 打印出这个潜在的错误,它会节省我几个小时::-/

Longer explanation When upgrading my monorepo, I somehow landed in a situation where one of the packages got removed from my packages.json, presumably because yarn couldn't resolve it (in my case this package was react-native-animated-pagination-dots ).更长的解释当升级我的 monorepo 时,我不知何故陷入了其中一个包从我的 packages.json 中删除的情况,大概是因为 yarn 无法解析它(在我的例子中,这个包是react-native-animated-pagination-dots ). Then the app which had this dependency started getting this error, the other app didn't.然后具有此依赖项的应用程序开始出现此错误,而另一个应用程序则没有。

use this command installing the node module first首先使用此命令安装节点模块
npm install --force npm 安装 --force

Then use npx react-native run-android然后使用 npx react-native run-android

for running the project用于运行项目

Happened to me earlier today because of mixing between npm and yarn package managers, a simple npm install solved this.由于 npm 和纱线 package 管理器之间的混合,今天早些时候发生在我身上,一个简单的npm 安装解决了这个问题。 No need to include --force flag.无需包含--force标志。

I'm not able to leave comments or upvotes yet.我还不能发表评论或点赞。 But wanted to register that the best solution for me was to follow what paneer_tikka has said.但想表明对我来说最好的解决方案是遵循paneer_tikka所说的。 I simply replicated that... tried again and got the real error message, telling me what was missing.我只是简单地复制了那个……再试一次,得到了真正的错误信息,告诉我缺少了什么。 It was just a matter of adding that and it worked.只需添加它就可以了。

https://stackoverflow.com/a/74655794/18455264[enter link description here][1] https://stackoverflow.com/a/74655794/18455264 [在此处输入链接描述][1]

I got this in an nx monorepo only for a specific app (but not others).我在一个 nx monorepo 中只为一个特定的应用程序(而不是其他应用程序)得到了这个。 None of the above methods worked for me.以上方法都不适合我。 Finally figured this -终于想通了——

TLDR; TLDR;

This is not the actual error (you probably guessed this).这不是真正的错误(您可能已经猜到了)。 This error message comes from node_modules/@react-native-community/cli/build/index.js OR node_modules/react-native/node_modules/@react-native-community/cli/build/index.js.此错误消息来自 node_modules/@react-native-community/cli/build/index.js 或 node_modules/react-native/node_modules/@react-native-community/cli/build/index.js。 To be sure, you can run this in node_modules directory: find.可以肯定的是,您可以在 node_modules 目录中运行它: -name '*.js' -print0 | -名称'*.js'-print0 | xargs -0 grep "Failed to load configuration of your project" 2. Edit these files to print the underlying error. xargs -0 grep "Failed to load configuration of your project" 2. 编辑这些文件以打印底层错误。

} catch (error) { /** * When there is no package.json found, the CLI will enter detached mode and a subset * of commands will be available. } catch (error) { /** * 当没有找到package.json时,CLI 将进入detached模式并且命令的子集 * 将可用。 That's why we don't throw on such kind of error.这就是为什么我们不会抛出这种错误。 */ if (error.message.includes("We couldn't find a package.json")) { _cliTools().logger.debug(error.message); */ if (error.message.includes("我们找不到 package.json")) { _cliTools().logger.debug(error.message);

  _cliTools().logger.debug('Failed to load configuration of your project. Only a subset of commands will be available.');
} else {
  //---> ***** Print the underlying error!
  console.log('=============>', error);
  throw new (_cliTools().CLIError)('Failed to load configuration of your project.', error);
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM