为什么npm install命令会在节点应用中一次又一次地重新运行?

时间:2017-11-25 14:02:38

标签: node.js amazon-web-services npm package.json

我经历了一个奇怪的情况。我在macOS Sierra 10.12.3中获得了一个节点应用程序。我还得到了以下信息:

node -v打印v8.4.0 npm -v打印5.3.0

package.json文件:

    {
  "name": "myapp",
  "version": "1.0.1",
  "description": "My Node App",
  "main": "app.js",
  "scripts": {
    "install": "npm install",
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
  },
  "engines": {
    "node": ">=6"
  },
  "author": "blackjack",
  "license": "ISC",
  "dependencies": {
    "angular": "^1.5.8"
  }
}

当我跑步" npm install"为了安装依赖项,安装了这些依赖项,然后," npm install"重播。实际上,它永远不会一次又一次地停止运行。

看看这个:

pathfinder:myapp blackjack$ npm install --loglevel verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   '--loglevel',
npm verb cli   'verbose' ]
npm info using npm@5.3.0
npm info using node@v8.4.0
npm verb npm-session 0695436488c367c7
npm info lifecycle myapp@1.0.1~preinstall: myapp@1.0.1
npm verb correctMkdir /Users/blackjack/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /Users/blackjack/.npm/_locks/staging-e02d0e92bf103f5a.lock for /Users/blackjack/dev/web/myapp/node_modules/.staging
npm verb unlock done using /Users/blackjack/.npm/_locks/staging-e02d0e92bf103f5a.lock for /Users/blackjack/dev/web/myapp/node_modules/.staging
npm info linkStuff myapp@1.0.1
npm verb linkBins myapp@1.0.1
npm verb linkMans myapp@1.0.1
npm info lifecycle myapp@1.0.1~install: myapp@1.0.1

> myapp@1.0.1 install /Users/blackjack/dev/web/myapp
> npm install

npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'install' ]
npm info using npm@5.3.0
npm info using node@v8.4.0
npm verb npm-session aeb46163714f97fa
npm info lifecycle myapp@1.0.1~preinstall: myapp@1.0.1
npm verb correctMkdir /Users/blackjack/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /Users/blackjack/.npm/_locks/staging-e02d0e92bf103f5a.lock for /Users/blackjack/dev/web/myapp/node_modules/.staging
npm verb unlock done using /Users/blackjack/.npm/_locks/staging-e02d0e92bf103f5a.lock for /Users/blackjack/dev/web/myapp/node_modules/.staging
npm info linkStuff myapp@1.0.1
npm verb linkBins myapp@1.0.1
npm verb linkMans myapp@1.0.1
npm info lifecycle myapp@1.0.1~install: myapp@1.0.1

> myapp@1.0.1 install /Users/blackjack/dev/web/myapp
> npm install

^C

它从不打印" OK"告诉它按预期工作。 在节点app.js"之后,应用程序运行正常。命令。但是,它会阻止在AWS Beanstalk中进行安装。我看不到任何错误。

2 个答案:

答案 0 :(得分:1)

从package.json中删除"install": "npm install",

正如您在the document中看到的那样,npm在安装软件包后运行此处指定的命令。因此,在此处指定npm install将永久运行npm install

答案 1 :(得分:1)

如果您谈论有角种子git存储库,则package.json中有"prestart":"npm-install"。您可以删除它以防止其重复运行。如果它在软件包文件中,那么即使您运行"npm start"命令,它也会同时运行"npm install"