将 NestJS 部署到 Azure DevOps:错误:找不到模块“../commands”

nob*_*are 5 node.js azure-devops azure-pipelines azure-pipelines-release-pipeline nestjs

我有一个非常基本的“Hello World”NestJS 应用程序,我正在尝试将其部署到 Azure DevOps 中的 Azure Web App 实例。

我已经使用 YAML 文件设置了一个构建管道,该文件输出带有distnode_modules目录的构建工件。

然后,在我的发布管道中,我设置了持续部署来下载该工件并部署它。发布管道包含部署 Azure 应用服务的单个步骤。此外,在此步骤之后,我输入了一些部署后操作npm install,其中npm update、 和npm run start:prod来启动 NestJS 服务器。

在此输入图像描述

然而,在运行管道时,该步骤花费了过多的时间,最终出现错误:

在此输入图像描述

当我访问已设置的 Web 应用程序实例 ( https://<project-name>.azurewebsites.net/) 时,我看到:

在此输入图像描述

因此,我单击“诊断资源”来尝试找出我的发布失败的原因,并最终发现此错误:

2020-05-29T20:01:30.864090341Z   _____                               
2020-05-29T20:01:30.864143041Z   /  _  \ __________ _________   ____  
2020-05-29T20:01:30.864149941Z  /  /_\  \___   /  |  \_  __ \_/ __ \ 
2020-05-29T20:01:30.864153741Z /    |    \/    /|  |  /|  | \/\  ___/ 
2020-05-29T20:01:30.864157341Z \____|__  /_____ \____/ |__|    \___  >
2020-05-29T20:01:30.864161141Z         \/      \/                  \/ 
2020-05-29T20:01:30.864164541Z A P P   S E R V I C E   O N   L I N U X
2020-05-29T20:01:30.864167941Z 
2020-05-29T20:01:30.864171141Z Documentation: http://aka.ms/webapp-linux
2020-05-29T20:01:30.864174441Z NodeJS quickstart: https://aka.ms/node-qs
2020-05-29T20:01:30.864177741Z NodeJS Version : v12.13.0
2020-05-29T20:01:30.864181041Z Note: Any data outside '/home' is not persisted
2020-05-29T20:01:30.864184441Z 
2020-05-29T20:01:30.951441760Z Oryx Version: 0.2.20191105.2, Commit: 67e159d71419415435cb5d10c05a0f0758ee8809, ReleaseTagName: 20191105.2
2020-05-29T20:01:30.951840160Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2020-05-29T20:01:30.951915661Z Could not find operation ID in manifest. Generating an operation id...
2020-05-29T20:01:30.952061661Z Build Operation ID: dfd18989-3b7b-4e2e-a64e-cf7310361e99
2020-05-29T20:01:32.750738663Z Writing output script to '/opt/startup/startup.sh'
2020-05-29T20:01:33.355033998Z Running #!/bin/sh
2020-05-29T20:01:33.359017599Z 
2020-05-29T20:01:33.359033399Z # Enter the source directory to make sure the script runs where the user expects
2020-05-29T20:01:33.359644199Z cd "/home/site/wwwroot"
2020-05-29T20:01:33.359658399Z 
2020-05-29T20:01:33.359664799Z export NODE_PATH=$(npm root --quiet -g):$NODE_PATH
2020-05-29T20:01:33.360538899Z if [ -z "$PORT" ]; then
2020-05-29T20:01:33.360552699Z         export PORT=8080
2020-05-29T20:01:33.360557899Z fi
2020-05-29T20:01:33.360561499Z 
2020-05-29T20:01:33.361582699Z npm start
2020-05-29T20:01:35.698639821Z 
2020-05-29T20:01:35.698668521Z > <project-name>@0.0.1 start /home/site/wwwroot
2020-05-29T20:01:35.698675121Z > nest start
2020-05-29T20:01:35.698679221Z 
2020-05-29T20:01:35.930729770Z internal/modules/cjs/loader.js:797
2020-05-29T20:01:35.930766970Z     throw err;
2020-05-29T20:01:35.930772870Z     ^
2020-05-29T20:01:35.930776770Z 
2020-05-29T20:01:35.930780670Z Error: Cannot find module '../commands'
2020-05-29T20:01:35.930784670Z Require stack:
2020-05-29T20:01:35.930788470Z - /home/site/wwwroot/node_modules/.bin/nest
2020-05-29T20:01:35.930792370Z     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
2020-05-29T20:01:35.930803370Z     at Function.Module._load (internal/modules/cjs/loader.js:687:27)
2020-05-29T20:01:35.930807770Z     at Module.require (internal/modules/cjs/loader.js:849:19)
2020-05-29T20:01:35.930811570Z     at require (internal/modules/cjs/helpers.js:74:18)
2020-05-29T20:01:35.930815370Z     at Object. (/home/site/wwwroot/node_modules/.bin/nest:5:20)
2020-05-29T20:01:35.930819770Z     at Module._compile (internal/modules/cjs/loader.js:956:30)
2020-05-29T20:01:35.930823570Z     at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
2020-05-29T20:01:35.930827470Z     at Module.load (internal/modules/cjs/loader.js:812:32)
2020-05-29T20:01:35.930831270Z     at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-05-29T20:01:35.930835070Z     at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10) {
2020-05-29T20:01:35.930838970Z   code: 'MODULE_NOT_FOUND',
2020-05-29T20:01:35.930842770Z   requireStack: [ '/home/site/wwwroot/node_modules/.bin/nest' ]
2020-05-29T20:01:35.930846670Z }
2020-05-29T20:01:35.970252977Z npm ERR! code ELIFECYCLE
2020-05-29T20:01:35.979824678Z npm ERR! errno 1
2020-05-29T20:01:35.981324478Z npm ERR! <project-name>@0.0.1 start: `nest start`
2020-05-29T20:01:35.982002178Z npm ERR! Exit status 1
2020-05-29T20:01:35.982641778Z npm ERR! 
2020-05-29T20:01:35.991823280Z npm ERR! Failed at the <project-name>@0.0.1 start script.
2020-05-29T20:01:35.991838780Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-29T20:01:36.118651500Z 
2020-05-29T20:01:36.119439400Z npm ERR! A complete log of this run can be found in:
2020-05-29T20:01:36.128548002Z npm ERR!     /root/.npm/_logs/2020-05-29T20_01_35_990Z-debug.log
Run Code Online (Sandbox Code Playgroud)

此时我无法弄清楚出了什么问题。任何帮助将不胜感激。

Jay*_*iel 9

您很可能正在使用默认npm start映射到的which 。nest start您将遇到的问题是@nestjs/clinest命令的来源)是默认情况下的一部分devDependencies,因此除非您移动了它,否则 Azure 可能会清理devDeps并保留产品部门。您应该使用node dist/main来启动您的应用程序,而不是在不增加依赖项的情况下消除此问题。否则,添加@nestjs/clidependencies应该修复它。

  • 这就是我所需要的。谢谢你! (2认同)