除非首先删除node_modules文件夹,否则NPM安装不起作用?

时间:2016-08-21 01:28:51

标签: node.js azure npm azure-devops

我有一个visual studio团队服务构建定义,第一步是“npm install”。此定义部署到azure Web应用程序。

NPM完成没有错误,但是在访问Web应用程序时,会抛出错误“找不到模块'express'”。当从“wwwroot”文件夹手动运行“npm install”时,web应用程序文件和package.json位于该文件夹中,命令再次成功完成,但错误仍然存​​在。

然而,当我从“wwwroot”文件夹中删除“node_modules”并再次运行“npm install”时,错误消失了,Web应用程序按预期运行!

如何修复构建定义,以便每次部署都不需要这些手动步骤?

我的package.json的相关摘录如下:

 "dependencies": {
    "express": "^4.13.4",
    "pug": "^2.0.0-alpha7",
    "bluebird": "^3.4.1",
},

npm日志位于以下位置:

    2016-08-21T01:19:28.9476070Z ##[debug]check path : C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.104.1\tasks\Npm\0.2.15\task.json
2016-08-21T01:19:28.9476070Z ##[debug]set resource file to: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.104.1\tasks\Npm\0.2.15\task.json
2016-08-21T01:19:28.9486073Z ##[debug]system.culture=en-US
2016-08-21T01:19:28.9646119Z ##[debug]check path : C:\Program Files\nodejs\npm.cmd
2016-08-21T01:19:28.9656074Z ##[debug]npm=C:\Program Files\nodejs\npm.cmd
2016-08-21T01:19:28.9666075Z ##[debug]cwd=C:\a\1\s
2016-08-21T01:19:28.9686074Z ##[debug]path exists: C:\a\1\s
2016-08-21T01:19:28.9696068Z ##[debug]command=install
2016-08-21T01:19:28.9696068Z ##[debug]C:\Program Files\nodejs\npm.cmd arg: install
2016-08-21T01:19:28.9706071Z ##[debug]arguments=null
2016-08-21T01:19:28.9706071Z ##[debug]exec tool: C:\Program Files\nodejs\npm.cmd
2016-08-21T01:19:28.9716073Z ##[debug]Arguments:
2016-08-21T01:19:28.9716073Z ##[debug]   install
2016-08-21T01:19:28.9726071Z [command]C:\Program Files\nodejs\npm.cmd install
2016-08-21T01:19:43.5330503Z smart-iot@1.0.0 C:\a\1\s
2016-08-21T01:19:43.5330503Z +-- azure-iot-device-amqp@1.0.10
2016-08-21T01:19:43.5340519Z | +-- azure-iot-amqp-base@1.0.10
2016-08-21T01:19:43.5340519Z | | +-- amqp10@3.2.2
2016-08-21T01:19:43.5340519Z | | | +-- node-amqp-encoder@0.0.2 
2016-08-21T01:19:43.5350499Z | | | +-- node-int64@0.4.0 
2016-08-21T01:19:43.5350499Z | | | `-- stately.js@1.3.0 
2016-08-21T01:19:43.5360508Z | | `-- amqp10-transport-ws@0.0.3
2016-08-21T01:19:43.5360508Z | |   `-- nodejs-websocket@1.6.0 
2016-08-21T01:19:43.5370502Z | `-- azure-iot-device@1.0.10
2016-08-21T01:19:43.5370502Z |   `-- azure-storage@1.1.0
2016-08-21T01:19:43.5370502Z |     `-- readable-stream@2.0.6
2016-08-21T01:19:43.5380497Z |       +-- process-nextick-args@1.0.7 
2016-08-21T01:19:43.5380497Z |       `-- util-deprecate@1.0.2 
2016-08-21T01:19:43.5390498Z +-- express@4.14.0
2016-08-21T01:19:43.5390498Z | +-- accepts@1.3.3
2016-08-21T01:19:43.5390498Z | | `-- mime-types@2.1.11
2016-08-21T01:19:43.5400508Z | |   `-- mime-db@1.23.0 
2016-08-21T01:19:43.5400508Z | +-- array-flatten@1.1.1 
2016-08-21T01:19:43.5420690Z | +-- content-disposition@0.5.1 
2016-08-21T01:19:43.5420690Z | +-- cookie-signature@1.0.6 
2016-08-21T01:19:43.5430497Z | +-- debug@2.2.0 
2016-08-21T01:19:43.5430497Z | | `-- ms@0.7.1 
2016-08-21T01:19:43.5440674Z | +-- depd@1.1.0 
2016-08-21T01:19:43.5440674Z | +-- escape-html@1.0.3 
2016-08-21T01:19:43.5450502Z | +-- etag@1.7.0 
2016-08-21T01:19:43.5450502Z | +-- finalhandler@0.5.0
2016-08-21T01:19:43.5460530Z | | `-- unpipe@1.0.0 
2016-08-21T01:19:43.5460530Z | +-- fresh@0.3.0 
2016-08-21T01:19:43.5470497Z | +-- merge-descriptors@1.0.1 
2016-08-21T01:19:43.5470497Z | +-- methods@1.1.2 
2016-08-21T01:19:43.5480496Z | +-- on-finished@2.3.0 
2016-08-21T01:19:43.5480496Z | | `-- ee-first@1.1.1 
2016-08-21T01:19:43.5490499Z | +-- parseurl@1.3.1 
2016-08-21T01:19:43.5490499Z | +-- path-to-regexp@0.1.7 
2016-08-21T01:19:43.5500513Z | +-- proxy-addr@1.1.2
2016-08-21T01:19:43.5500513Z | | `-- forwarded@0.1.0 
2016-08-21T01:19:43.5500513Z | +-- send@0.14.1
2016-08-21T01:19:43.5510491Z | | +-- destroy@1.0.4 
2016-08-21T01:19:43.5510491Z | | `-- mime@1.3.4 
2016-08-21T01:19:43.5520499Z | +-- type-is@1.6.13
2016-08-21T01:19:43.5520499Z | | `-- media-typer@0.3.0 
2016-08-21T01:19:43.5520499Z | `-- utils-merge@1.0.0 
2016-08-21T01:19:43.5530492Z `-- pug@2.0.0-beta4
2016-08-21T01:19:43.5530492Z   +-- pug-code-gen@0.0.7 
2016-08-21T01:19:43.5540495Z   | +-- doctypes@1.1.0 
2016-08-21T01:19:43.5540495Z   | +-- js-stringify@1.0.2 
2016-08-21T01:19:43.5540495Z   | +-- pug-attrs@2.0.1 
2016-08-21T01:19:43.5550503Z   | `-- void-elements@2.0.1 
2016-08-21T01:19:43.5550503Z   +-- pug-filters@1.2.3
2016-08-21T01:19:43.5550503Z   | +-- clean-css@3.4.19
2016-08-21T01:19:43.5560494Z   | | `-- source-map@0.4.4 
2016-08-21T01:19:43.5560494Z   | |   `-- amdefine@1.0.0 
2016-08-21T01:19:43.5570499Z   | +-- jstransformer@1.0.0
2016-08-21T01:19:43.5570499Z   | | +-- is-promise@2.1.0 
2016-08-21T01:19:43.5570499Z   | | `-- promise@7.1.1 
2016-08-21T01:19:43.5580491Z   | +-- pug-walk@0.0.3 
2016-08-21T01:19:43.5580491Z   | +-- resolve@1.1.7 
2016-08-21T01:19:43.5590498Z   | `-- uglify-js@2.7.0
2016-08-21T01:19:43.5590498Z   |   +-- source-map@0.5.6 
2016-08-21T01:19:43.5590498Z   |   +-- uglify-to-browserify@1.0.2 
2016-08-21T01:19:43.5600495Z   |   `-- yargs@3.10.0 
2016-08-21T01:19:43.5600495Z   |     +-- camelcase@1.2.1 
2016-08-21T01:19:43.5600495Z   |     +-- cliui@2.1.0 
2016-08-21T01:19:43.5610497Z   |     | +-- center-align@0.1.3 
2016-08-21T01:19:43.5610497Z   |     | | +-- align-text@0.1.4 
2016-08-21T01:19:43.5620497Z   |     | | | +-- kind-of@3.0.4 
2016-08-21T01:19:43.5620497Z   |     | | | | `-- is-buffer@1.1.4 
2016-08-21T01:19:43.5620497Z   |     | | | +-- longest@1.0.1 
2016-08-21T01:19:43.5630568Z   |     | | | `-- repeat-string@1.5.4 
2016-08-21T01:19:43.5630568Z   |     | | `-- lazy-cache@1.0.4 
2016-08-21T01:19:43.5640500Z   |     | +-- right-align@0.1.3 
2016-08-21T01:19:43.5640500Z   |     | `-- wordwrap@0.0.2 
2016-08-21T01:19:43.5640500Z   |     +-- decamelize@1.2.0 
2016-08-21T01:19:43.5650495Z   |     `-- window-size@0.1.0 
2016-08-21T01:19:43.5650495Z   +-- pug-lexer@2.0.2
2016-08-21T01:19:43.5660502Z   | +-- character-parser@2.2.0 
2016-08-21T01:19:43.5660502Z   | | `-- is-regex@1.0.3 
2016-08-21T01:19:43.5660502Z   | `-- is-expression@2.1.0
2016-08-21T01:19:43.5670500Z   |   `-- object-assign@4.1.0 
2016-08-21T01:19:43.5670500Z   +-- pug-parser@2.0.1
2016-08-21T01:19:43.5670500Z   | `-- token-stream@0.0.1 
2016-08-21T01:19:43.5680491Z   `-- pug-strip-comments@0.0.1 
2016-08-21T01:19:43.5680491Z     `-- pug-error@0.0.0 
2016-08-21T01:19:43.5820489Z ##[debug]rc:0
2016-08-21T01:19:43.5820489Z ##[debug]success:true
2016-08-21T01:19:43.5830501Z ##[debug]task result: Succeeded
2016-08-21T01:19:43.6100505Z Finishing task: Npm

例如,“express”模块文件夹缺少其“index.js”,“LICENSE”和“package.json”文件,原因不明。

1 个答案:

答案 0 :(得分:1)

我试图利用 npm install > 存档文件> 复制和发布构建工件> Azure Web应用程序部署工作流程以安装程序包,打包应用程序并部署到Azure Web App。

enter image description here

以下是详细的构建步骤参数:

  • enter image description here

  • enter image description here

  • enter image description here

  • enter image description here

您可以参考https://www.visualstudio.com/docs/release/examples/nodejs/node-to-azure-webapps#build了解有关在类似情况下在VSTS中构建和部署工作流程的更多信息。