无法从 react-script 卸载 webpack [英] Cannot uninstall webpack from react-script
问题描述
我试图在 React 中制作一个 todo-app,这对我来说是新的.但是一旦安装了 webpack,npm start 就不起作用了.它给了我:
I was trying to make a todo-app in react, which is new to me. But after once installed webpack, npm start doesnt working. It gives me:
my-todo-react@0.1.0 start/home/hanna/Desktop/projects/my-todo-react反应脚本开始
my-todo-react@0.1.0 start /home/hanna/Desktop/projects/my-todo-react react-scripts start
项目依赖树可能有问题.这可能不是 Create React App 中的错误,而是您需要在本地修复的问题.
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 提供的 react-scripts 包需要一个依赖:
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.19.1"
"webpack": "4.19.1"
不要尝试手动安装:您的包管理器会自动安装.但是,在树的更高位置检测到了不同版本的 webpack:
Don't try to install it manually: your package manager does it automatically. However, a different version of webpack was detected higher up in the tree:
/home/hanna/node_modules/webpack(版本:4.20.2)
/home/hanna/node_modules/webpack (version: 4.20.2)
众所周知,手动安装不兼容的版本会导致难以调试的问题.
Manually installing incompatible versions is known to cause hard-to-debug issues.
如果更愿意忽略此检查,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中.这将永久禁用此消息,但您可能会遇到其他问题.
If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. 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:
- 删除项目文件夹中的 package-lock.json(不是 package.json!)和/或 yarn.lock.
- 删除项目文件夹中的 node_modules.
- 从项目文件夹的 package.json 文件中的依赖项和/或 devDependencies 中删除webpack".
- 运行 npm install 或 yarn,具体取决于您使用的包管理器.
在大多数情况下,这应该足以解决问题.如果这没有帮助,您还可以尝试其他一些方法:
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:
如果您使用 npm,请安装 yarn (http://yarnpkg.com/) 并重复用上面的步骤代替.这可能会有所帮助,因为 npm 存在包提升方面的已知问题,这些问题可能会在未来版本中得到解决.
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions.
检查/home/hanna/node_modules/webpack 是否在您的项目目录之外.例如,您可能不小心在主文件夹中安装了某些东西.
Check if /home/hanna/node_modules/webpack is outside your project directory. For example, you might have accidentally installed something in your home folder.
尝试在您的项目文件夹中运行 npm ls webpack.这将告诉您哪些其他包(除了预期的 react-scripts)安装了 webpack.
Try running npm ls webpack in your project folder. This will tell you which other package (apart from the expected react-scripts) installed webpack.
如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中.这将永久禁用此预检检查,以防您仍想继续.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permanently disable this preflight check in case you want to proceed anyway.
附言我们知道此消息很长,但请阅读上述步骤 :-) 我们希望它们对您有所帮助!
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm 错误!代码生命周期npm 错误!错误号 1npm 错误!my-todo-react@0.1.0 start: react-scripts start
npm 错误!退出状态 1npm 错误!npm 错误!在 my-todo-react@0.1.0 启动脚本失败.npm 错误!这可能不是 npm 的问题.上面可能有额外的日志输出.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-todo-react@0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-todo-react@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm 错误!可以在以下位置找到此运行的完整日志:npm 错误!/home/hanna/.npm/_logs/2018-10-02T10_39_06_361Z-debug.log
npm ERR! A complete log of this run can be found in: npm ERR! /home/hanna/.npm/_logs/2018-10-02T10_39_06_361Z-debug.log
推荐答案
在项目根目录创建一个.env
文件,并添加这一行SKIP_PREFLIGHT_CHECK=true
文件内.
Create a .env
file in the root directory of the project and add this line SKIP_PREFLIGHT_CHECK=true
inside the file.
然后尝试运行yarn start
.
这篇关于无法从 react-script 卸载 webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!