Node failes to install tools via "npm install" - node.js

I am running windows 7 - 64 bit
after running latest node installer, and typing
npm install
I get errors
Couldn't read dependencies
ENOENT open ....packages.json
wtf?

npm install installs the dependencies listed in your package.json. The error you get means that the folder you are currently in does not have a package.json.

You should ideally be using a file called package.json (not packages.json) to follow convention. Also that file may be missing. Please create a package.json and check the notation is correct in the JSON file.
'npm install' looks for dependencies listed in package.json file and then pulls them from npm registry into the local ./node_modules folder.

Related

npm install does not work because certain package does not contain a package.json file

I am trying to run npm install for a cloned project and it errors out with this error: Could not install from "node_modules/#miksu/prettier/parse-srcset#github:ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee" as it does not contain a package.json file
I don't have /node_modules in this directory since this is the first npm i for this project on my local computer. Also I am using vscode and I have this in the package.lock file #miksu/prettier but i don't have prettier in the package.json as a package to install. Let me know what other information is needed. Thanks!
Edit: I deleted the #miksu/prettier entry from package-lock.json and that allowed npm i to run successfully, but I'm still not sure what is going on with this error. Any clarity is appreciated, thanks.
I mean... the package it self doesnt contain a package.json

Why is "npm install" looking for a file that doesn't exist (package.json) on a fresh NodeJS installation?

Hello, World!
I am having trouble getting NPM working.
First, I installed node.js from https://nodejs.org/en/download/ (the 64-bit .msi, on Windows 10, Version 10.0.18362 Build 18362). Node -v is 12.16.3.
Using Powershell, I navigated to the nodejs directory created in the install. Then I attempted npm install, which ultimately drew a series of errors beginning with "ENOENT: no such file or directory, open '...\nodejs\package.json' ".
The nodejs directory contains a file called "package-lock.json", but no "package.json".
Renaming the "-lock" file did not fix the error.
I've read on this site that Node came with NPM pre-installed. I can run npm -v without a problem ("6.14.4" returned) but trying npm start gives me the same error as npm install (cannot find package.json).
I have uninstalled Node & reinstalled twice, same problem.
Thoughts?
You should create a package.json file for every project using npm libraries, whether or not you are going to publish your code anywhere.
The easiest way is to run npm init and answer the questions, then npm will create the package.json file.
(Or take a look at the docs for other ways to run init, like npm init -y to just generate a plain package.json that you can manually edit.)
BTW, package-lock.json is a different kind of file that's generated to say which versions of each transitive dependency were installed. It doesn't have the same format as package.json; don't mix them.

Cannot uninstall webpack from react-script

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

Npm Install straight from package.json

I have a simple question that i cant seem to find the answer for. I cloned a git repo to my local machine.
When attempting to start node, I receive an error because i don't have the required npm dependencies installed. However, they are located in the packages.json file that was cloned.
I was wondering if there was a simple way to install the dependencies located in that file, without having to npm install for every individual package.
Within the directory of the package.json file, just run npm install. It will read package.json and install all dependencies. If you want to limit it to only non-dev dependencies, use npm install --only=production.

Why after "npm install express" there is no package.json in my directory?

I am using latest version of nodejs, 0.10.24
I followed this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/how-to-scrape-web-pages-with-node-js-and-jquery/
after installing npm install express, I can't find the package.json file in the same directory.
But when I tried this on Windows a few months before, I noticed that there was a file in the same directory.
Is there anything I need to do to fix?
Thanks,
When you npm install module ,the only goal is to download and save the module in ./node_module/ directory.
If you want get a package.json, you must use npm init and fill all the information asked.
After that, you can make npm install module --save, that command will download and add the module in your package.json.

Resources