android目录下的./gradlew clean
命令也有问题。我试过降级npm版本,但没有帮助。什么好主意吗?
下面是我运行npx react-native run-android
时得到的日志:
error Failed to load configuration of your project.
Error: Cannot find module '...node_modulesjson-parse-better-errorsindex.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:projectsBeautynode_modulesparse-jsonindex.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)
环境:
操作系统:Windows 10
react native: 0.65.1
Node: 14.17.4
npm: 7.23.0
使用此命令先安装节点模块
npm install --force
之后使用
npx react-native run-android
用于运行项目
今天早些时候发生在我身上,因为npm和yarn包管理器之间的混合,一个简单的npm install
解决了这个问题。不需要包含--force
标志
我在nx monorepo
中只得到了一个特定的应用程序(但不是其他)。以上方法对我都不起作用。终于想到了这个-
TLDR;
- 这不是实际的错误(您可能猜到了)。此错误信息来自
node_modules/@react-native-community/cli/build/index.js
或node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
。
为了确保,您可以在node_modules目录: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);
}
}
- 对于我来说,这打印为:
=============> [CLIError: Node module directory for package react-native-animated-pagination-dots was not found]
我所要做的就是修复
yarn add react-native-animated-pagination-dots
。如果CLI打印出这个潜在的错误,就可以节省我几个小时!: -/再解释在升级我的monorepo时,我遇到了一个情况,其中一个软件包从我的软件包中删除了。json,大概是因为yarn无法解决它(在我的情况下,这个包是react-native-animated-pagination-dots
)。然后有这个依赖的应用程序开始得到这个错误,另一个应用程序没有。
-
删除node_modules文件夹
-
运行以下命令
npm install --legacy-peer-deps
npm run android
或npx react-native run-android