npm install 永远循环

问题描述 投票:0回答:2

我在为我正在处理的项目运行 npm install 时遇到问题。

它似乎不断地重新运行 npm install 命令(直到手动终止)。奇怪的是,在第一次 npm install 之后,所有依赖项都已安装并正常工作。当尝试使用一些 CI 工具自动构建我的代码时,这成为一个问题。

我已在以下条件下对此进行了测试;

  • Windows 操作系统
  • Linux操作系统
  • 各种 Node/NPM 版本(6.x 和 8.x 分支)
  • 只有一个依赖项的简单 package.json。
  • 清除 npm 缓存

当前使用的node/npm版本;

  • 节点:v6.11.5
  • NPM:2010年10月3日

显示问题的简单 package.json:

{
  "name": "tool",
  "version": "1.0.0",
  "author": "Jeff",
  "description": "A starter project",
  "repository": {},
  "license": "UNLICENSED",
  "contributors": [],
  "keywords": [],
  "dependencies": {
    "@angular/common": "4.4.6"
  },
  "devDependencies": {
  },
  "scripts": {
    "install": "npm install",
    "serve-dev": "ng serve --host 0.0.0.0",
    "serve-prod": "ng serve --prod --host 0.0.0.0",
    "build-dev": "ng build",
    "build-prod": "ng build --prod"
  }
}

NPM 安装日志:

npm -dd install
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node', '/usr/bin/npm', '-dd', 'install' ]
npm info using [email protected]
npm info using [email protected]
npm verb mapToRegistry no registry URL found in name for scope @angular
npm verb request uri https://registry.npmjs.org/@angular%2fcommon
npm verb request no auth needed
npm info attempt registry request try #1 at 3:41:11 PM
npm verb request id 10054e4c6c4b8242
npm verb etag W/"59f29d79-234ca"
npm verb lastModified Fri, 27 Oct 2017 02:44:09 GMT
npm http request GET https://registry.npmjs.org/@angular%2fcommon
npm http 304 https://registry.npmjs.org/@angular%2fcommon
npm verb headers { date: 'Fri, 27 Oct 2017 23:41:13 GMT',
npm verb headers   via: '1.1 varnish',
npm verb headers   'cache-control': 'max-age=0',
npm verb headers   etag: 'W/"59f29d79-234ca"',
npm verb headers   age: '0',
npm verb headers   connection: 'keep-alive',
npm verb headers   'x-served-by': 'cache-mdw17339-MDW',
npm verb headers   'x-cache': 'MISS',
npm verb headers   'x-cache-hits': '0',
npm verb headers   'x-timer': 'S1509147674.967823,VS0,VE358',
npm verb headers   vary: 'Accept-Encoding' }
npm verb etag https://registry.npmjs.org/@angular%2fcommon from cache
npm verb get saving @angular/common to /home/jeff/.npm/registry.npmjs.org/_40angular_252fcommon/.cache.json
npm verb correctMkdir /home/jeff/.npm correctMkdir not in flight; initializing
npm verb cache add spec @angular/[email protected]
npm verb addNamed "4.4.6" is a plain semver version for @angular/common
npm verb mapToRegistry no registry URL found in name for scope @angular
npm verb addNameVersion registry:https://registry.npmjs.org/@angular%2fcommon not in flight; fetching
npm verb get https://registry.npmjs.org/@angular%2fcommon not expired, no request
npm verb afterAdd /home/jeff/.npm/@angular/common/4.4.6/package/package.json not in flight; writing
npm verb correctMkdir /home/jeff/.npm correctMkdir not in flight; initializing
npm verb afterAdd /home/jeff/.npm/@angular/common/4.4.6/package/package.json written
npm verb request uri https://registry.npmjs.org/tslib
npm verb request no auth needed
npm info attempt registry request try #1 at 3:41:14 PM
npm verb etag W/"59dd9f6d-4c68"
npm verb lastModified Wed, 11 Oct 2017 04:34:53 GMT
npm http request GET https://registry.npmjs.org/tslib
npm http 304 https://registry.npmjs.org/tslib
npm verb headers { date: 'Fri, 27 Oct 2017 23:41:15 GMT',
npm verb headers   via: '1.1 varnish',
npm verb headers   'cache-control': 'max-age=300',
npm verb headers   etag: 'W/"59dd9f6d-4c68"',
npm verb headers   age: '172',
npm verb headers   connection: 'keep-alive',
npm verb headers   'x-served-by': 'cache-mdw17339-MDW',
npm verb headers   'x-cache': 'HIT',
npm verb headers   'x-cache-hits': '1',
npm verb headers   'x-timer': 'S1509147675.077783,VS0,VE0',
npm verb headers   vary: 'Accept-Encoding, Accept' }
npm verb etag https://registry.npmjs.org/tslib from cache
npm verb get saving tslib to /home/jeff/.npm/registry.npmjs.org/tslib/.cache.json
npm verb correctMkdir /home/jeff/.npm correctMkdir not in flight; initializing
npm verb cache add spec tslib@^1.7.1
npm verb addNamed ">=1.7.1 <2.0.0" is a valid semver range for tslib
npm verb addNameRange registry:https://registry.npmjs.org/tslib not in flight; fetching
npm verb get https://registry.npmjs.org/tslib not expired, no request
npm verb addNamed "1.8.0" is a plain semver version for tslib
npm verb afterAdd /home/jeff/.npm/tslib/1.8.0/package/package.json not in flight; writing
npm verb correctMkdir /home/jeff/.npm correctMkdir not in flight; initializing
npm verb afterAdd /home/jeff/.npm/tslib/1.8.0/package/package.json written
npm info lifecycle [email protected]~preinstall: [email protected]
npm verb correctMkdir /home/jeff/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /home/jeff/.npm/_locks/staging-950641377131bc6f.lock for /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging
npm verb unbuild node_modules/.staging/@angular/common-b1bc935a
npm verb unbuild node_modules/.staging/tslib-34a2ed6e
npm verb gentlyRm don't care about contents; nuking /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/@angular/common-b1bc935a
npm verb gentlyRm don't care about contents; nuking /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/tslib-34a2ed6e
npm verb tar unpack /home/jeff/.npm/@angular/common/4.4.6/package.tgz
npm verb tar unpacking to /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/@angular/common-b1bc935a
npm verb gentlyRm don't care about contents; nuking /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/@angular/common-b1bc935a
npm verb tar unpack /home/jeff/.npm/tslib/1.8.0/package.tgz
npm verb tar unpacking to /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/tslib-34a2ed6e
npm verb gentlyRm don't care about contents; nuking /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/tslib-34a2ed6e
npm verb gentlyRm don't care about contents; nuking /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/tslib-34a2ed6e/node_modules
npm verb gentlyRm don't care about contents; nuking /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging/@angular/common-b1bc935a/node_modules
npm info lifecycle [email protected]~preinstall: [email protected]
npm info lifecycle @angular/[email protected]~preinstall: @angular/[email protected]
npm info linkStuff [email protected]
npm verb linkBins [email protected]
npm verb linkMans [email protected]
npm info linkStuff @angular/[email protected]
npm verb linkBins @angular/[email protected]
npm verb linkMans @angular/[email protected]
npm info lifecycle [email protected]~install: [email protected]
npm info lifecycle @angular/[email protected]~install: @angular/[email protected]
npm info lifecycle [email protected]~postinstall: [email protected]
npm info lifecycle @angular/[email protected]~postinstall: @angular/[email protected]
npm verb unlock done using /home/jeff/.npm/_locks/staging-950641377131bc6f.lock for /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging
npm info linkStuff [email protected]
npm verb linkBins [email protected]
npm verb linkMans [email protected]
npm info lifecycle [email protected]~install: [email protected]

> [email protected] install /mnt/c/work/personal/LiveXSLTransformUI/tmp
> npm install

npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node', '/usr/bin/npm', 'install' ]
npm info using [email protected]
npm info using [email protected]
npm info lifecycle [email protected]~preinstall: [email protected]
npm verb correctMkdir /home/jeff/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /home/jeff/.npm/_locks/staging-950641377131bc6f.lock for /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging
npm verb unlock done using /home/jeff/.npm/_locks/staging-950641377131bc6f.lock for /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging
npm info linkStuff [email protected]
npm verb linkBins [email protected]
npm verb linkMans [email protected]
npm info lifecycle [email protected]~install: [email protected]

> [email protected] install /mnt/c/work/personal/LiveXSLTransformUI/tmp
> npm install

npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node', '/usr/bin/npm', 'install' ]
npm info using [email protected]
npm info using [email protected]
npm info lifecycle [email protected]~preinstall: [email protected]
npm verb correctMkdir /home/jeff/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /home/jeff/.npm/_locks/staging-950641377131bc6f.lock for /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging
npm verb unlock done using /home/jeff/.npm/_locks/staging-950641377131bc6f.lock for /mnt/c/work/personal/LiveXSLTransformUI/tmp/node_modules/.staging
npm info linkStuff [email protected]
npm verb linkBins [email protected]
npm verb linkMans [email protected]
npm info lifecycle [email protected]~install: [email protected]
node.js npm installation
2个回答
15
投票

正如 R. Richards 所指出的那样。删除“安装”脚本行修复了它。如果你的 pacakge.json 中有的话,似乎会陷入一些永久循环!


0
投票

我今天自己也遇到了这个问题,如果其他人遇到这个问题,我想提供解决方案的变体。

TL;DR; 由于

install
是关键字,您唯一需要做的就是将脚本名称更改为不同的名称,例如
"install:main": "npm install"
。但如果仅此而已,我就会删除脚本本身。


在我的项目中,我们在执行

--legacy-peer-deps
时仍然坚持运行
npm install
。因此,当我需要进行全新安装时,我厌倦了忘记将其放入其中。那是我在OP遇到同样问题的时候。所以我补充道:

"install": "npm install --legacy-peer-deps"

这又导致了无限循环,现在我知道了,这是可以理解的,我使用了关键字并得到了异常结果。

但我仍然不想回到旧的方式,我目前正在设置一个安装命令,该命令将有更多的标志或更少的标志,具体取决于我正在做什么(不会进入这里的情况非常复杂)。

所以我决定的是:

"install:legadcy-peer-deps": "npm install --legacy-peer-deps"

这让我重新开始工作。

© www.soinside.com 2019 - 2024. All rights reserved.