node.js 无法从 react-script 卸载 webpack

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52606707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:55:10  来源:igfitidea点击:

Cannot uninstall webpack from react-script

node.jsreactjsreact-nativenpmwebpack

提问by Hanna Kogut

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:

我试图在 React 中制作一个 todo-app,这对我来说是新的。但是一旦安装了 webpack,npm start 就不起作用了。它给了我:

[email protected] start /home/hanna/Desktop/projects/my-todo-react react-scripts start

[email protected] start /home/hanna/Desktop/projects/my-todo-react react-scripts start

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 包需要一个依赖:

"webpack": "4.19.1"

"webpack": "4.19.1"

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:

不要尝试手动安装:您的包管理器会自动安装。但是,在树的更高位置检测到了不同版本的 webpack:

/home/hanna/node_modules/webpack (version: 4.20.2)

/home/hanna/node_modules/webpack(版本:4.20.2)

Manually installing incompatible versions is known to cause hard-to-debug issues.

众所周知,手动安装不兼容的版本会导致难以调试的问题。

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.

如果更愿意忽略此​​检查,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。这将永久禁用此消息,但您可能会遇到其他问题。

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.
  2. Delete node_modules in your project folder.
  3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.
  1. 删除项目文件夹中的 package-lock.json(不是 package.json!)和/或 yarn.lock。
  2. 删除项目文件夹中的 node_modules。
  3. 从项目文件夹中的 package.json 文件中的依赖项和/或 devDependencies 中删除“webpack”。
  4. 运行 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:

在大多数情况下,这应该足以解决问题。如果这没有帮助,您还可以尝试其他一些方法:

  1. 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.

  2. Check if /home/hanna/node_modules/webpack is outside your project directory. For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls webpack in your project folder. This will tell you which other package (apart from the expected react-scripts) installed webpack.

  1. 如果您使用 npm,请安装 yarn ( http://yarnpkg.com/) 并用它重复上述步骤。这可能会有所帮助,因为 npm 存在已知的包提升问题,这些问题可能会在未来版本中得到解决。

  2. 检查 /home/hanna/node_modules/webpack 是否在您的项目目录之外。例如,您可能不小心在主文件夹中安装了某些东西。

  3. 尝试在您的项目文件夹中运行 npm ls webpack。这将告诉您安装了 webpack 的其他包(除了预期的 react-scripts)。

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.

如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。如果您无论如何都想继续,这将永久禁用此预检检查。

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

PS 我们知道这条消息很长,但请阅读上面的步骤 :-) 我们希望它们对您有所帮助!

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] start: react-scripts startnpm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm 错误!代码 ELIFECYCLE npm ERR!错误号 1 npm 错误号![email protected] 开始:react-scripts startnpm ERR!退出状态 1 npm ERR!npm 错误!在 [email protected] 启动脚本失败。npm 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。

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

错误!可以在以下位置找到此运行的完整日志:npm ERR!/home/hanna/.npm/_logs/2018-10-02T10_39_06_361Z-debug.log

回答by Pedro Junior

To solve this issue I had to uninstall webpack and webpack-dev-server from the node-modules folder and then install them again but with different versions.

为了解决这个问题,我必须从 node-modules 文件夹中卸载 webpack 和 webpack-dev-server,然后再次安装它们,但使用不同的版本。

  1. Open cmd on the node-modules folder outside of your project folder

  2. Uninstall webpack and webpack-dev-server:

    npm uninstall webpack
    npm uninstall webpack-dev-server
    
  3. Delete the node-modulesfolder and the package-lock.jsonfile from your project's folder.

  4. Open the node-modules again

    npm install [email protected]
    npm install [email protected]
    
  5. Use this command on your project folder

    npm install
    
  1. 项目文件的 node-modules 文件夹上打开 cmd

  2. 卸载 webpack 和 webpack-dev-server:

    npm uninstall webpack
    npm uninstall webpack-dev-server
    
  3. 从项目文件夹中删除node-modules文件夹和package-lock.json文件。

  4. 再次打开节点模块

    npm install [email protected]
    npm install [email protected]
    
  5. 在您的项目文件夹上使用此命令

    npm install
    

It did the trick for me, hope it helps you too.

它对我有用,希望它也能帮助你。

回答by Sanjeet kumar

Create a .envfile in the root directory of the project and add this line SKIP_PREFLIGHT_CHECK=trueinside the file.

.env在项目的根目录中创建一个文件,并SKIP_PREFLIGHT_CHECK=true在文件中添加这一行。

then try to run yarn start.

然后尝试运行yarn start

回答by zetriks

I had similar problem today. I resolved with the following steps:

我今天遇到了类似的问题。我通过以下步骤解决了:

  1. Execute npm ls webpack--> to find out that I have installed Webpack outside my folder ("like yours ... /home/hanna/node_modules/webpack).
  2. Then cdinto that location (/home/hanna/node_modules/) and execute npm install [email protected]. That way I have the same version of Webpack like in my project folder.
  1. 执行npm ls webpack--> 以发现我已经在我的文件夹之外安装了 Webpack(“就像你的...... /home/hanna/node_modules/webpack)。
  2. 然后cd进入该位置(/home/hanna/node_modules/)并执行npm install [email protected]. 这样我的项目文件夹中就有了相同版本的 Webpack。

After that, when I run npm start, it works fine.

之后,当我运行时npm start,它工作正常。

回答by Atav32

Since it looks like the project uses Create React App, Webpack is probably already a dependency in the package.json. So the easy way to install it is to just go to the project directory and type npm install(or yarn install) in the terminal.

由于看起来项目使用 Create React App,Webpack 可能已经是package.json. 因此,安装它的简单方法是转到项目目录并在终端中键入npm install(或yarn install)。

If using the Webpack CLI causes errors, it's probably because there's a different version installed globally.

如果使用 Webpack CLI 导致错误,可能是因为全局安装了不同的版本。

To uninstall it globally, type npm -g uninstall webpack.

要全局卸载它,请键入npm -g uninstall webpack

回答by altostraus

One solution I had was to go to my "Home" folder and delete the node_modules folder and package-lock.json file.

我的一种解决方案是转到我的“主页”文件夹并删除 node_modules 文件夹和 package-lock.json 文件。

Worked afterwards.

后来工作了。

回答by Kranti Brid

Go to your project directory where you are running npm startand run the command

转到您正在运行的项目目录npm start并运行命令

touch .env

touch .env

If there is no pre-existing .env file in your project this will create it. Got to .env file and add the following code (if you are on LINUX box you do this by typing nano .envotherwise just use a text editor. SKIP_PREFLIGHT_CHECK=true

如果您的项目中没有预先存在的 .env 文件,这将创建它。转到 .env 文件并添加以下代码(如果您在 LINUX 框中,则可以通过键入来执行此操作,nano .env否则只需使用文本编辑器。 SKIP_PREFLIGHT_CHECK=true

Save the file and try running npm startagain. This solution is exactly what is suggested in the error message and it worked for me

保存文件并npm start再次尝试运行 。这个解决方案正是错误消息中建议的,它对我有用

回答by Serkan AKMAN

If someone still facing this issue and uses yarn instead of npm can do (I am a mac user):

如果有人仍然面临这个问题并使用 yarn 而不是 npm 可以做到(我是 mac 用户):

  • Open a terminal
  • Type yarn remove webpack
  • Come in to your project directory using your file explorer
  • Delete everything there
  • Open your code-editor
  • Delete hidden filers (ETC: .env or .gitignore files) if exists
  • In your project directory open a terminal and type npx create-react-app .and hit enter.
  • And restart the app typing yarn startafter download.
  • 打开终端
  • 类型 yarn remove webpack
  • 使用文件资源管理器进入您的项目目录
  • 删除那里的所有内容
  • 打开你的代码编辑器
  • 如果存在,删除隐藏的文件管理器(ETC:.env 或 .gitignore 文件)
  • 在您的项目目录中打开一个终端并输入npx create-react-app .并按回车键。
  • yarn start在下载后重新启动应用程序。

It worked for me. It downloaded the web pack which is needed from react-scripts.

它对我有用。它从 react-scripts 下载了所需的 web 包。

回答by Afroz Atoz

Go to /home/hannaand type npm i webpack@required_dependency. It should solve your problem.

转到/home/hanna并键入npm i webpack@required_dependency。它应该可以解决您的问题。

回答by Ridha Rezzag

I couldn't find a way to uninstall the whole node module folder the only way is to delete the whole file using command line

我找不到卸载整个节点模块文件夹的方法,唯一的方法是使用命令行删除整个文件

rm -rf node_modules

回答by rodrigo rodrigues

I think if you have a webpack package installed globally it might cause such error. Removing it globally might solve the problem. That's what I did here and it works.

我认为如果您全局安装了 webpack 包,则可能会导致此类错误。全局删除它可能会解决问题。这就是我在这里所做的并且有效。