Why do Node modules go into .staging folder?
node.jsElectronpackage.jsonnode.js Problem Overview
I have an Electron app that I'm trying to install node modules for. When I run npm install
, it creates the node_modules
folder but all the modules go into a subfolder called .staging
. Each module also has -xxxxx
appended to it, where the x's are some random alphanumerics.
Other Electron apps I've created have never done this. All the node modules sit in the root of node_modules
and don't have -xxxxx
appended.
Any idea why this is happening?
node.js Solutions
Solution 1 - node.js
I was also facing the same issue, I tried the steps below:
-
Delete package-lock.json
-
Delete Node Modules folder
-
Try installing it using below command (should be in open network)
npm install
Note: - ".staging" means, those dependencies are getting downloaded so for the temporary basis it keeps all those dependencies under ".staging" folder. Once all gets downloaded properly then it will showcase them under node_modules only.
I hope this will work.
Solution 2 - node.js
This only happens temporarily until the modules are downloaded and installed. Node seems to do this so it can place together common submodules from all the modules you are installing so it can better structure the node modules folder(mainly for windows users).
If this is happening after an npm install finishes it is likely that there is something wrong with your node installation or something in the install failed.
Solution 3 - node.js
If you're automatically installing node_modules using CI/CD you should check out npm ci. Also check out this Stackoverflow question.
npm ci
The documentation points out the differences between npm install
and npm ci
.
- The project must have an existing
package-lock.json
ornpm-shrinkwrap.json
- If dependencies in the package lock do not match those in
package.json
,npm ci
will exit with an error, instead of updating the package lock. npm ci
can only install entire projects at a time: individual dependencies cannot be added with this command.- If a
node_modules
is already present, it will be automatically removed beforenpm ci
begins its install. This is nice, because it prevents having to do something likerm -rf node_modules
. - It will never write to
package.json
or any of the package-locks: installs are essentially frozen.
Solution 4 - node.js
-
Delete package.lock.json
-
Delete node_modules
-
run
npm update
Solution 5 - node.js
I was having 2 versions of node installed on my system.
nodejs v4.2
and node v8.6
I thought this could be conflicting, so I deleted nodejs v4.2
with following commands.
sudo apt-get remove nodejs
and linked the path with
sudo ln -s /usr/bin/node /usr/bin/nodejs
Again I ran npm install
and it got fixed
Solution 6 - node.js
This worked for me I moved the project from C drive to other drive and ran the following commands take a backup of older node modules if you are running this and existing project
npm clear cache --force
npm update
Solution 7 - node.js
.staging is a temporary npm folder, where the modules are temporarily saved while they are being downloaded, if the package.json downloads are still not completed, the created folder remains, until the installation is complete.
The problem may be lack of space on your hard drive.
Solution 8 - node.js
I faced similar issue and tried the above answers but it did'nt worked for me; I followed below steps to resolve this issue-
1.npm audit
By running npm audit I got list of pending packages to install-
2.npm i packagename
After installing one or two package one by one from list, I used
3.npm install
At this time the installation went smooth without any lag or hangup. Hope this help who is facing similar issue :).
Solution 9 - node.js
If you have a windows machine where you do not posses Admin rights to it.
Try deleting node_modules and install using 'npm install'
from command line as
'ADMINISTRATOR'
It works!
Anyways, it comes down to an open network thing ;)