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

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

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

我已经使用YAML文件建立了构建管道,该文件输出具有distnode_modules目录的构建工件。

然后,在我的发布管道中,我设置了连续部署,以下载该工件并进行部署。发布管道仅包含一个步骤即可部署Azure App Service。此外,在此步骤之后,我输入了一些部署后操作npm installnpm updatenpm run start:prod来启动NestJS服务器。

enter image description here

但是,当运行管道时,该步骤花费了过多的时间,最终导致错误:

enter image description here

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

enter image description here

因此,我单击“诊断资源”以试图弄清楚我的发行失败的原因并最终发现此错误:

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

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

node.js azure-devops azure-pipelines nestjs azure-pipelines-release-pipeline
1个回答
0
投票

[很有可能,您正在使用npm start,默认情况下它映射到nest start。您将遇到的问题是,默认情况下,@nestjs/clinest命令的来源)是devDependencies的一部分,因此,除非您将其移动,否则Azure可能会擦洗devDeps并保持产品部门。您应该使用node dist/main来启动您的应用,以消除此问题而不会膨胀您的依赖项。否则,将@nestjs/cli添加到dependencies应该可以解决。

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