简体   繁体   中英

Deploying NestJS to Azure DevOps: Error: Cannot find module '../commands'

I have a very basic "Hello World" NestJS app that I'm trying to get deployed to an Azure Web App instance in Azure DevOps.

I have set up a build pipeline using a YAML file which outputs a build artifact with the dist and node_modules directories.

Then, in my release pipeline, I have a continuous deployment set up to download that artifact and deploy it. The release pipeline consists of a single step to Deploy Azure App Service. Furthermore, after this step, I entered some Post-Deployment Actions which are npm install , npm update , and npm run start:prod to get the NestJS server started.

在此处输入图像描述

However, when running the pipeline, that step takes an inordinate amount of time eventually erroring with:

在此处输入图像描述

When I visit the web app instance that I have set up ( https://<project-name>.azurewebsites.net/ ), I see:

在此处输入图像描述

So, I click on "Diagnostic Resources" to try to figure out why my release is failing and eventually discover this error:

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

At this point I can't figure out what is wrong. Any help would be greatly appreciated.

More than likely, you're using npm start which is mapped to nest start by default. The problem you'll run into with this is that @nestjs/cli (where the nest command comes from) is a part of devDependencies by default, so unless you've moved it, Azure is probably scrubbing the devDeps and keeping on prod deps. You should be using node dist/main to start your app instead to remove this problem without bloating your dependencies. Otherwise, adding @nestjs/cli to dependencies should fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM