node.js 为什么 Node 模块会进入 .staging 文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44573592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:17:23  来源:igfitidea点击:

Why do Node modules go into .staging folder?

node.jselectronpackage.json

提问by 4thSpace

I have an Electron app that I'm trying to install node modules for. When I run npm install, it creates the node_modulesfolder but all the modules go into a subfolder called .staging. Each module also has -xxxxxappended to it, where the x's are some random alphanumerics.

我有一个 Electron 应用程序,我正在尝试为其安装节点模块。当我运行时npm install,它会创建node_modules文件夹,但所有模块都进入一个名为.staging. 每个模块还-xxxxx附加了它,其中 x 是一些随机的字母数字。

Other Electron apps I've created have never done this. All the node modules sit in the root of node_modulesand don't have -xxxxxappended.

我创建的其他电子应用程序从未这样做过。所有节点模块都位于 的根目录中node_modules并且没有-xxxxx附加。

Any idea why this is happening?

知道为什么会这样吗?

回答by thomasmeadows

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).

这只会在下载并安装模块之前暂时发生。Node 似乎这样做,因此它可以将您正在安装的所有模块的公共子模块放在一起,以便它可以更好地构建节点模块文件夹(主要用于 Windows 用户)。

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.

如果在 npm install 完成后发生这种情况,则可能是您的节点安装有问题或安装失败。

回答by atul parate

I was also facing the same issue, I tried the steps below:

我也遇到了同样的问题,我尝试了以下步骤:

  1. Delete package-lock.json
  2. Delete Node Modules folder
  3. Try installing it using below command (should be in open network)

    npm install
    
  1. 删除 package-lock.json
  2. 删除节点模块文件夹
  3. 尝试使用以下命令安装它(应该在开放网络中)

    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.

注意:-“.staging”意味着,这些依赖项正在被下载,因此临时将所有这些依赖项保存在“.staging”文件夹下。一旦所有内容都正确下载,它将仅在 node_modules 下展示它们。

I hope this will work.

我希望这会奏效。

回答by CloudBranch

If you're automatically installing node_modules using CI/CD you should check out npm ci. Also check out thisStackoverflow question.

如果您使用 CI/CD 自动安装 node_modules,您应该查看npm ci。另请查看Stackoverflow 问题。

npm ci

The documentation points out the differences between npm installand npm ci.

该文件指出,之间的差异npm installnpm ci

  • The project must have an existing package-lock.jsonor npm-shrinkwrap.json
  • If dependencies in the package lock do not match those in package.json, npm ciwill exit with an error, instead of updating the package lock.
  • npm cican only install entire projects at a time: individual dependencies cannot be added with this command.
  • If a node_modulesis already present, it will be automatically removed before npm cibegins its install. This is nice, because it prevents having to do something like rm -rf node_modules.
  • It will never write to package.jsonor any of the package-locks: installs are essentially frozen.
  • 该项目必须具有现有package-lock.jsonnpm-shrinkwrap.json
  • 如果包锁中的依赖项与 中的不匹配package.jsonnpm ci将退出并显示错误,而不是更新包锁。
  • npm ci一次只能安装整个项目:无法使用此命令添加单个依赖项。
  • 如果 anode_modules已经存在,它将在npm ci开始安装之前自动删除。这很好,因为它可以防止必须执行类似rm -rf node_modules.
  • 它永远不会写入package.json或任何包锁:安装基本上是冻结的。

回答by Aarvy

I was having 2 versions of node installed on my system. nodejs v4.2and node v8.6

我的系统上安装了 2 个版本的节点。 nodejs v4.2node v8.6

I thought this could be conflicting, so I deleted nodejs v4.2with following commands.

我认为这可能是冲突的,所以我nodejs v4.2用以下命令删除了。

sudo apt-get remove nodejs

and linked the path with

并将路径与

sudo ln -s /usr/bin/node /usr/bin/nodejs

Again I ran npm installand it got fixed

我又跑了npm install,它得到了修复

回答by Vino

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

1.npm audit

By running npm audit I got list of pending packages to install-

通过运行 npm audit 我得到了待安装的软件包列表 -

2.npm i packagename

2.npm i packagename

After installing one or two package one by one from list, I used

从列表中一一安装一两个包后,我使用

3.npm install

3.npm install

At this time the installation went smooth without any lag or hangup. Hope this help who is facing similar issue :).

此时安装顺利,没有任何滞后或挂断。希望这对面临类似问题的人有所帮助:)。

回答by franky stein

  1. Delete package.lock.json

  2. Delete node_modules

  3. run npm update

  1. 删除 package.lock.json

  2. 删除 node_modules

  3. npm update

回答by Pankaj Shrivastava

If you have a windows machine where you do not posses Admin rights to it.

如果您有一台 Windows 机器,但您不拥有它的管理员权限。

Try deleting node_modules and install using 'npm install'from command line as

尝试删除 node_modules 并使用'npm install'命令行安装

'ADMINISTRATOR'

'行政人员'

It works!

有用!

Anyways, it comes down to an open network thing ;)

无论如何,这归结为一个开放的网络事物;)

回答by Soft Dev Ahmad yar khan

step 1.Delete package-lock.json

步骤1.删除package-lock.json

step 2.Delete node_modules

步骤 2.删除 node_modules

step 3.THEN, npm install(in project folder)

步骤 3.THEN,npm install(在项目文件夹中)

Definitely worked 100%...

绝对工作100%......