简体   繁体   English

需要帮助解决我不断收到的 react.js 错误

[英]Need help on a react.js error that I keep on getting

Every time I try running npm start on a new project I keep on getting this error.每次我尝试在新项目上运行 npm start 时,我都会收到此错误。 Does anyone know or have any idea how to fix this??有谁知道或知道如何解决这个问题?

There might be a problem with the project dependency tree.项目依赖树可能有问题。 It is likely not a bug in Create React App, but something you need to fix locally.这可能不是 Create React App 中的错误,而是您需要在本地修复的问题。

The react-scripts package provided by Create React App requires a dependency: Create React App 提供的 react-scripts package 需要依赖:

"babel-jest": "^26.6.0" “通天笑话”:“^26.6.0”

Don't try to install it manually: your package manager does it automatically.不要尝试手动安装它:您的 package 经理会自动安装。 However, a different version of babel-jest was detected higher up in the tree:然而,在树的更高层检测到不同版本的 babel-jest:

D:\node_modules\babel-jest (version: 24.9.0) D:\node_modules\babel-jest(版本:24.9.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.已知手动安装不兼容的版本会导致难以调试的问题。

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an.env file in your project.如果您希望忽略此检查,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 an.env 文件中。 That will permanently disable this message but you might encounter other issues.这将永久禁用此消息,但您可能会遇到其他问题。

To fix the dependency tree, try following the steps below in the exact order:要修复依赖关系树,请尝试按确切顺序执行以下步骤:

  1. Delete package-lock.json (not package.json.) and/or yarn.lock in your project folder.删除项目文件夹中的 package-lock.json(不是 package.json。)和/或 yarn.lock。
  2. Delete node_modules in your project folder.删除项目文件夹中的 node_modules。
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.从项目文件夹中 package.json 文件的依赖项和/或 devDependencies 中删除“babel-jest”。
  4. Run npm install or yarn, depending on the package manager you use.运行 npm install 或 yarn,具体取决于您使用的 package 管理器。

In most cases, this should be enough to fix the problem.在大多数情况下,这应该足以解决问题。 If this has not helped, there are a few other things you can try:如果这没有帮助,您可以尝试其他一些方法:

  1. If you used npm, install yarn ( http://yarnpkg.com/ ) and repeat the above steps with it instead.如果您使用 npm,请安装 yarn ( http://yarnpkg.com/ ) 并用它重复上述步骤。 This may help because npm has known issues with package hoisting which may get resolved in future versions.这可能会有所帮助,因为 npm 已知 package 提升的问题可能会在未来的版本中得到解决。

  2. Check if D:\node_modules\babel-jest is outside your project directory.检查 D:\node_modules\babel-jest 是否在你的项目目录之外。 For example, you might have accidentally installed something in your home folder.例如,您可能不小心在主文件夹中安装了一些东西。

  3. Try running npm ls babel-jest in your project folder.尝试在项目文件夹中运行 npm ls babel-jest。 This will tell you which other package (apart from the expected react-scripts) installed babel-jest.这将告诉您其他哪些 package(除了预期的 react-scripts)安装了 babel-jest。

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an.env file in your project.如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 an.env 文件中。 That would permanently disable this preflight check in case you want to proceed anyway.如果您仍然想继续,那将永久禁用此预检检查。

PS We know this message is long but please read the steps above:-) We hope you find them helpful! PS 我们知道这条消息很长,但请阅读上面的步骤:-) 我们希望它们对您有所帮助!

npm ERR. npm 错误。 code ELIFECYCLE npm ERR.代码 ELIFECYCLE npm 错误。 errno 1 npm ERR: react-portfolio@0.1.0 start: react-scripts start npm ERR. errno 1 npm ERR: react-portfolio@0.1.0 start: react-scripts start npm ERR。 Exit status 1 npm ERR.退出状态 1 npm ERR。 npm ERR. npm 错误。 Failed at the react-portfolio@0.1.0 start script. react-portfolio@0.1.0 启动脚本失败。 npm ERR! npm 错误! This is probably not a problem with npm.这可能不是 npm 的问题。 There is likely additional logging output above.上面可能还有其他日志记录 output。

npm ERR: A complete log of this run can be found in: npm ERR! npm ERR:此运行的完整日志可在以下位置找到:npm ERR!
C:\Users\smaso\AppData\Roaming\npm-cache_logs\2021-01-26T22_50_48_484Z-debug.log C:\Users\smaso\AppData\Roaming\npm-cache_logs\2021-01-26T22_50_48_484Z-debug.log

just go to your project's root directory and delete node_module folder and npm start your project.只需将 go 到您项目的根目录并删除 node_module 文件夹,然后 npm 即可启动您的项目。

I also face this problem.我也面临这个问题。 Simple solution of this problem is: 1)create.env file.这个问题的简单解决方法是: 1)创建.env 文件。 2) add SKIP_PREFLIGHT_CHECK=true in the file. 2)在文件中添加SKIP_PREFLIGHT_CHECK=true 3) npm start 3)npm启动

Delete and redownload node modules and run application again删除并重新下载节点模块并再次运行应用程序

If this fails to work, create a.env file in the root directory of your project and add the following line如果这不起作用,请在项目的根目录中创建一个 .env 文件并添加以下行

SKIP_PREFLIGHT_CHECK=true

Seems like you created the react project using create-react-app and installed jest using the following command.好像您使用 create-react-app 创建了 react 项目并使用以下命令安装了 jest。

yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react react-test-renderer yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react react-test-renderer

But in the documentation it says just to run the following command if you are using create-react-app但是在文档中,它说如果您使用的是 create-react-app,只需运行以下命令

yarn add --dev react-test-renderer yarn add --dev react-test-renderer

[See the documentation][1]https://jestjs.io/docs/tutorial-react [查看文档][1]https://jestjs.io/docs/tutorial-react

This worked for me.这对我有用。

I used the following command to uninstall jest npm uninstall jest in the root project folder (not the client) and then used the react scripts start command npm start and it worked我使用以下命令在根项目文件夹(不是客户端)中卸载 jest npm 卸载 jest ,然后使用反应脚本启动命令npm 启动并且它工作

removing jest.config.js and uninstall ts-jest solved my problem删除jest.config.js并卸载ts-jest解决了我的问题

To fix the dependency tree, try following the steps below in the exact order:要修复依赖关系树,请尝试按确切顺序执行以下步骤:

  1. Delete package-lock.json (not package.json.) and/or yarn.lock in your project folder.删除项目文件夹中的 package-lock.json(不是 package.json。)和/或 yarn.lock。
  2. Delete node_modules in your project folder.删除项目文件夹中的 node_modules。
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.从项目文件夹中 package.json 文件中的依赖项和/或 devDependencies 中删除“babel-jest”。
  4. Run npm install or yarn, depending on the package manager you use.运行 npm install 或 yarn,具体取决于您使用的 package 管理器。

In most cases, this should be enough to fix the problem.在大多数情况下,这应该足以解决问题。 If this has not helped, there are a few other things you can try:如果这没有帮助,您可以尝试其他一些方法:

  1. If you used npm, install yarn ( http://yarnpkg.com/ ) and repeat the above steps with it instead.如果您使用 npm,请安装 yarn ( http://yarnpkg.com/ ) 并用它重复上述步骤。 This may help because npm has known issues with package hoisting which may get resolved in future versions.这可能会有所帮助,因为 npm 已知 package 提升问题,这些问题可能会在未来的版本中得到解决。

  2. Check if./babel-jest is outside your project directory.检查./babel-jest 是否在您的项目目录之外。 For example, you might have accidentally installed something in your home folder.例如,您可能不小心在主文件夹中安装了一些东西。

  3. Try running npm ls babel-jest in your project folder.尝试在项目文件夹中运行 npm ls babel-jest。 This will tell you which other package (apart from the expected react-scripts) installed babel-jest.这将告诉您哪些其他 package(除了预期的 react-scripts)安装了 babel-jest。

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

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