When I npm install package, npm says that it successfully installed the package, but when I look for it in the node_modules folder, the package is not in the folder. When I npm install -g package, the package gets installed into the global /node_modules folder, so I have to drag the package from the global folder to the local folder.
Why is npm install not installing into my local /node_modules folder?
step 1) rm -rf ./node_modules from your root directory.
step 2) npm install.
The above commands first deletes your node_modules and then reinstalls all the packages that are found inside your package.json.
This is the same problem I was facing, both the above commands resolved the problem in my case.
If the above solution does not work in your case :
The problem is :
Data is not being fetched from the package.json, you must check whether you have written the correct statement or not inside your package.json.
There are a few things you can do to resolve this problem, as mentioned here.
First, try deleting your package-lock.json file. If you run npm install or npm i after that it should generate a brand new installation with no reference to an existing package-lock.json file.
If that doesn't work, try deleting your node_modules directory in your project. Then run npm install or npm i.
If THAT doesn't work, you should try deleting both the node_modules directory AND the package-lock.json. Then run npm install or npm i. This should resolve the issue.
Suppose, I do npm install and then I change the node version and then again do npm install, will the installed packages in package-lock.json and node_modules change? (Assuming the packages were not updated on the npm registry meanwhile)
Was curious about this myself, so I switched node versions, deleted yarn.lock and node_modules in my project, and then re-installed. Zero updates were made to the yarn.lock file
I just want to install socket.io to my project which is located on 3.chat folder. But when I run following command it shows following Warnings.And its not created a node_modules directory inside my project folder. How to fix this?
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io
C:\Users\Nuwanst
`-- socket.io#2.0.3
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'
npm WARN Nuwanst No description
npm WARN Nuwanst No repository field.
npm WARN Nuwanst No README data
npm WARN Nuwanst No license field.
If you already have package-lock.json file just delete it and try again.
Have you created a package.json file? Maybe run this command first again.
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm init
It creates a package.json file in your folder.
Then run,
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io --save
The --save ensures your module is saved as a dependency in your package.json file.
Let me know if this works.
Make sure you are on the right directory where you have package.json
You need to make sure that the package.json file exist in the app directory. Run this command where package.json file exists.
For more explanation, I run npm start in c:\selfPractice, but my package.json is in c:\selfPractice\frontend. When I switch to c:\selfPractice, it works.
NOTE: if you are experiencing this issue in your CI pipeline, it is usually because npm runs npm ci instead of npm install. npm ci requires an accurate package-lock.json.
To fix this, whenever you are modifying packages in package.json (e.g. moving packages from devDependencies to Dependencies like I was doing) you should regenerate package-lock.json in your repository by running these commands locally, and then push the changes upstream:
rm -rf node_modules
npm install
git commit package-lock.json
git push
If your folder already have package.json
Then,
Copy the path of package.json
Open terminal
Write:
cd your_path_to_package.json
Press ENTER
Then Write:
npm install
This worked for me
finally, I got a solution if you are getting:-
**npm WARN tar ENOENT: no such file or directory,.......**
then it is no issue of npm or its version it is os permission issue to resolve this you need to use below command:-
sudo chown -R $USER:$USER *
additional
sudo chmod -R 777 *
then run:-
sudo npm i
If you're trying to npm install on a folder that's being rsync'd from somewhere else, remember to add this to your rsync --exclude
yourpath/node_modules
Otherwise, NPM will try to add node_modules and rsync will remove it immediately, causing many npm WARN enoent ENOENT: no such file or directory, open errors.
Delete package.json and package-lock.json file
Then type npm init
after that type npm install socket.io --save
finally type npm install
It works for me
update version in package.json is working for me
I just experienced this error but on looking for the answer online here on stackoverflow I found the answer in the process so I decided to share it also , If this error occurs on a react project you are working on and when you run npm start make sure to change directory into the directory that has react installed in it and it will start working
if your node_modules got installed in say /home/UserName/ like in my case,
your package-lock.json file will also be there. just delete this file, go back to your app folder and run npm init and then npm install <pkgname> (e.g express) and a new node_modules folder will be created for your.
I had this in a new project on Windows. npm install had created a node_modules folder for me, but it had somehow created the folder without giving me full control over it. I gave myself full control over node_modules and node_modules\.staging and it worked after that.
Seems you have installed express in root directory.Copy path of package.json and delete package json file and node_modules folder.
I had the same problem, I resolved by removing all insignificant lines in packages.json e only left "name", "version", "description", "devDependencies", "dependencies", "resolutions". and the error was gone.
the file path you ran is wrong. So if you are working on windows, go to the correct file location with cd and rerun from there.
I need to generate a yarn.lock file from my package.json but I want to avoid node_modules creation. Is it possible?
EDIT: Please check the comment below for a solution without the need for any additional package thanks to #talon55 : npm install --package-lock-only; yarn import
Old answer:
This is actually one of the few features that NPM has (npm install --package-lock-only) and Yarn does not support.
It is a heavily requested feature as you can tell from these 2 open Github issues: 5738 and 2340
I stumbled upon the command yarn generate-lock-entry documented in here but it definitely does not do what we are looking for.
The workaround I would suggest is generating an NPM lock file and converting it to a yarn.lock file using synp:
npm install -g synp
npm install --package-lock-only
synp --source-file package-lock.json
Please note that Synp requires the the packages to be installed and that the node_modules is rightly populated. This may, or may not be, a problem to your use case.
Available since yarn v3.0.0-rc.10
yarn install --mode update-lockfile
yarn generate-lock-entry > yarn.lock
Running npm update updates items listed in package.json; however, the dependencies of those items are still outdated.
The obvious workaround is to run npm update once more. Sometimes I need to run it 3+ times to have clean npm outdated. Is there a flag in npm update to perform a deep update?
Another extreme workaround is to reinstall
rm -rf node_modules
npm install
Update
It has bee 5 years, and I am still running the code above with the addition of rm package-lock.json when I really need to shake it. Seeing "red lines" in npm out output after npm up is no longer a problem.
As an ugly workaround I have this function defined in my ~/.bash_profile
function up {
npm remove --save "$1";
npm install --save "$1";
}
So whenever I want to update a dependency I just run up express or up yourFavoritePackage
If you take a look at the directory structure in node_modules you will notice that each module has its own subdir node_modules for its dependencies. You shouldn't need to run "npm update" more than once.