问题
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?
回答1:
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.
回答2:
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.
回答3:
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
回答4:
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 :).
回答5:
Delete package.lock.json
Delete node_modules
run
npm update
回答6:
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 ;)
回答7:
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.
来源:https://stackoverflow.com/questions/44573592/why-do-node-modules-go-into-staging-folder