Cannot uninstall webpack from react-script - node.js

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
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.
The react-scripts package provided by Create React App requires a dependency:
"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:
/home/hanna/node_modules/webpack (version: 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.
To fix the dependency tree, try following the steps below in the exact order:
Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
Delete node_modules in your project folder.
Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
Run npm install or yarn, depending on the package manager you use.
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:
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.
Check if /home/hanna/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
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 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 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

Create a .env file in the root directory of the project and add this line SKIP_PREFLIGHT_CHECK=true inside the file.
then try to run yarn start.

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.
Open cmd on the node-modules folder outside of your project folder
Uninstall webpack and webpack-dev-server:
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node-modules folder and the package-lock.json file from your project's folder.
Open the node-modules again
npm install webpack#4.19.1
npm install webpack-dev-server#3.1.9
Use this command on your project folder
npm install
It did the trick for me, hope it helps you too.

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

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.
If using the Webpack CLI causes errors, it's probably because there's a different version installed globally.
To uninstall it globally, type npm -g uninstall webpack.

I had similar problem today. I resolved with the following steps:
Execute npm ls webpack --> to find out that I have installed Webpack outside my folder ("like yours ... /home/hanna/node_modules/webpack).
Then cd into that location (/home/hanna/node_modules/) and execute npm install webpack#4.19.1.
That way I have the same version of Webpack like in my project folder.
After that, when I run npm start, it works fine.

Go to your project directory where you are running npm start and run the command
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 .env otherwise just use a text editor.
SKIP_PREFLIGHT_CHECK=true
Save the file and try running npm start again.
This solution is exactly what is suggested in the error message and it worked for me

do this
first code in terminal this -->
yarn add --dev dotenv
create .env file in root directory then add below line in the .env file
SKIP_PREFLIGHT_CHECK=true

Go to /home/hanna and type npm i webpack#required_dependency. It should solve your problem.

If someone still facing this issue and uses yarn instead of npm can do (I am a mac user):
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 start after download.
It worked for me. It downloaded the web pack which is needed from react-scripts.

I encountered the same issue and following worked for me:
Delete the node-modules folder and package-lock.json file
Downloaded and installed Node.js
npm install webpack#4.19.1
npm install webpack-dev-server#3.1.9
Deleted babel-eslint entry from package.json
Used this command on the project folder: npm install
Finally yarn start or npm start

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.
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node_modules folder and the package-lock.json file from your root directory
##thompsonmax##
Then you can now run your command to your app,
create-react-app react-app

Step 1: Create an .env file in the root directory
Step 2: add this line into your .env file: SKIP_PREFLIGHT_CHECK=true
Step 3:Again npm start

After a lot of trials, I found that the easiest solution is to install the required version of webpack in /home/hanna.
That is,
cd to /home/hanna
run npm i webpack#4.19.1
Then, the error will go away. Hope it helps.

Your problem is you installed webpack version: 4.20.2
You need to install an earlier version "webpack": "4.19.1"`
Your problem is you installed webpack version: 4.20.2
You need to install an earlier version "webpack": "4.19.1"` ..So
$npm uninstall -g webpack
and
$npm install -g webpack#4.19.1
Hope that helps

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.

Due to newer versions, this worked for me:
Open a terminal window (command prompt) on the node_modules folder outside of your project folder
Uninstall webpack and webpack-dev-server:
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node_modules folder and the package-lock.json file from your project's folder.
Open node_modules again
npm install webpack#4.28.3
npm install webpack-dev-server#3.1.14
Use this command in your project folder:
npm install

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

npx create-react-app nameOfYourApp
find where is your nameOfYourApp and replace src folder with one from previous project
use new nameOfYourApp

If you have multiple node_modules folders with different versions of dependencies one may conflict with the other - do the following:
Follow steps 1-4 that are initially provided in project directory and commit updated changes locally~
i. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
ii. Delete node_modules in your project folder.
iii. Remove webpack from dependencies and/or devDependencies in the package.json file in your project folder.
iv. Run npm install or yarn, depending on the package manager you use.
Find the location of the node_modules folder that is not in your project folder ~ this line - (/home/hanna/node_modules/webpack)
Delete it
npm start
should work :)!

I also faced this issue. I had to install webpack#4.42.0 in the node_modules but after I installed webpack#4.42.0 there was an error displayed in the CMD:
`-- UNMET PEER DEPENDENCY webpack#4.42.0
npm ERR! peer dep missing: webpack#^5.1.0, required by terser-webpack-plugin#5.2.4
So installing webpack for node_modules didn't work. Then I used .env file to solve this.
First I typed npm add --dev dotenv in the project terminal.
Then I created the .env file and typed this code:
SKIP_PREFLIGHT_CHECK=true

Related

Problem with installing react dependencies

I am trying to install react using this command: npx create-react-app .
Then I tried to run using this command: npm run start
Then I get this error:
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.
The react-scripts package provided by Create React App requires a dependency:
"webpack-dev-server": "3.10.3"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack-dev-server was detected higher up in the tree:
C:\Users\oa\Desktop\node_modules\webpack-dev-server (version: 3.11.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.
That will permanently disable this message but you might encounter other issues.
As suggested here [https://stackoverflow.com/questions/42308879/npm-err-code-elifecycle][1] ,
I have tried to fix it using the following commands:
delete package-lock.json
npm cache clean --force
npm install
npm start
But did not fixed for me.
Just to let you know, my npm version is 6.13.6, and node version is v13.8.0
Try to create a .env file in the root directory of the project and add this line SKIP_PREFLIGHT_CHECK=true inside the file.
then try to run yarn start or npm start.
Did you give a project name after npx create-react-app 'appName' ?
If you have multiple node_modules folders with different versions of dependencies one may conflict with the other - do the following:
Follow steps 1-4 that are initially provided in project directory and commit updated changes locally~
i. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
ii. Delete node_modules in your project folder.
iii. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
iv. Run npm install or yarn, depending on the package manager you use.
Find the location of the node_modules folder that is not in your project folder ~ this line - (C:\Users\oa\Desktop\node_modules\webpack-dev-server)
Go there and delete it
once done try npm start
should work :)!

Cannot start npm/yarn

I decided to create React app under Linux and I've used those commands:
npm install -g create-react-app
create-react-app my_app_name
npm start
At this point I've recieved message:
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.
The react-scripts package provided by Create React App requires a dependency:
"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:
/home/ktw/node_modules/webpack (version: 4.24.0)
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.
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.
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:
5. 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.
6. Check if /home/ktw/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
I've done literally every step from this list but unfortunately - with no results.
I've already tried:
chown -R user: node_modules,
npm cache clean --force,
rm -rf node_modules && rm ./package-lock.json && npm install
and I have no idea what is going on.
Do you guys have any idea how to fix that?
It looks like you may have forgotten to do Step #3: Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
If you are doing the steps as you outline above, when you do npm install again, because Webpack is still in your package.json, it'll reinstall and continue the issue.

npm ERR! cb() never called! error when trying to run npm install command

I have this react-native project I worked on my other pc, and I want now to keep working on this exact project folder in my other linux machine.
So now I have the project folder, which doesn't contain node_modules directory, but it does contain "package.json". As I understood it, doing NPM install inside the directory, should install and create the node_modules directory with all the needed dependencies.
However, the operation is failed after a while with the error "npm ERR! cb() never called!"
I've already tried to clean npm cache (with -f flag) but it doesn't worked for me.
I'm running on Ubuntu 18.04 based os with Node.js v8.10.0 and npm v3.5.2.
In my case, I had an own custom node_module which is in my package.json like that:
// ...
"dependencies": {
// ...
"my-module": "file:../../my-module",
},
// ...
This package is only available in a specific environment (dynamically added to package.json via npm install ../../my-module), which is by intend,
but I forgot about it and when I ran npm install in another environment (where my module was not available)
the mysteriuos cb() never called error occured.
After putting the option --no-package-lock behind the npm install the error got more clear, telling me that it has something to do with my-module.
see also: https://stackoverflow.com/a/52474959/3063191
Hope this helps :)
I my case i was able to fix it by deleting
node_modules
package-lock.json
and then running npm install
I had similar issue for git project. The Project configuration had created bad .npmrc file, which was preventing package installation. I resolved it by deleting the .npmrc file, then performing hte following steps:
Delete the node_modules folder from project, if it exists
Delete temp files from machine
Run npm cache clean --force
Run npm install
Manually delete the package-lock.json file and then run "npm install". It should re-generate the package-lock.json.
let me save your time , Just install latest Nodejs. I was trying all day. Finally this solved

Create package.json from package-lock.json

I downloaded a theme and it has a package-lock.json file but no package.json file.
Is there a way I can generate the package.json from the package-lock.json file.
How do I install the node modules with just the package-lock.json file.
Is there a way to do that?
Warning: Do not attempt before reading comments below & backup package-lock.json.
Install the latest npm with npm install -g npm
Run npm init and respond to the questions.
The above command will generate a package.json and include the existing packages listed in package-lock.json
I think I figured it out.
I don't think npm init can draw from package-lock.json. However it does seem to pull from what is already in your /node_modules. I believe this is why #Harry B's solution works for some and not at all for others.
For example, if you have just cloned your project which contains package-lock.json, no package.json, and empty/non-existence node_modules, npm init won't create any dependencies. However, if you run npm install pkg1 pkg2 pkg3 ... then run npm init it will create the dependencies in package.json.
https://pravnyadv.github.io/unpackage/ seems to work. Copy your package lock file text in, hit the button, copy out the text into a new package.json file.
package-lock.json file relies on the presence of a package.json file, So it's not possible to retrieve package.json (happy to be proved wrong).
So a possible solution left is to use a module like auto-install which is capable of generating package.json from the project file dependencies.
First, you need to install the module globally npm install -g auto-install. Then run npm init and answer the basic requirements.
Then, run auto-install in your project root directory. All the dependencies should reflect in package.json file.
**
Or Install node modules directly from package-lock.json
**
Run npm ci which bypasses a package’s package.json to install modules from a package’s lockfile.
More Information

How do I stop npm (v5.3.0) from automatically clearing local modules after install/uninstall?

I just upgrade my npm to v5.3.0 and run into a problem: after I install/uninstall a module, npm would automatically clear my local modules that I manually put into my node_modules. These local modules are not included into package.json. This is really annoying. Please help, thanks.
The solution is similar to the question How To Specify Local Modules As NPM Package Dependencies. The command is "npm install [path-to-local-module] --save". The local modules will be copied into the node_modules folder and their dependencies will be added to package.json.

Resources