0

I am trying to deploy a nodejs app onto Azure App Service. I did the basics of deploying it, but it's failing to run. It seems it is designed to run "node run.js" commands rather than "npm run start".

I'm playing in the console, and if I try to run npm run start manually, I get a series of errors tied to build. Basically:

'tsc' is not recognized as an internal or external command

I'm wondering if there's something really obvious here about how tsc (and others) can be added to path. I have to admit, I'm not particularly well versed in using Azure or Node for that matter. Any help would be very much appreciated! Thanks!

This is the package.json file:

{
  "name": "test-scraper",
  "version": "0.1.1",
  "description": "",
  "main": "dist/main.js",
  "scripts": {
    "build": "tsc",
    "build:dev": "tsc --watch",
    "prestart": "npm run build",
    "start:dev": "nodemon",
    "start": "pm2 start dist/src/main.js --node-args=\"-r ./tsconfig-paths-bootstrap.js\" && pm2 monit",
    "stop": "pm2 delete main"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "@types/lodash": "^4.14.161",
    "@types/node": "^14.11.8",
    "@types/puppeteer": "^3.0.2",
    "nodemon": "^2.0.4",
    "prettier": "^2.1.2",
    "typescript": "^4.0.3"
  },
  "dependencies": {
    "axios": "^0.20.0",
    "discord-webhook-node": "^1.1.8",
    "lodash": "^4.17.20",
    "messaging-api-telegram": "^1.0.1",
    "playwright-firefox": "^1.4.2",
    "pm2": "^4.5.0",
    "tsconfig-paths": "^3.9.0",
    "winston": "^3.3.3"
  }
}

user3787031
  • 177
  • 1
  • 3
  • 12
  • 1
    If my answer not help, please post your `package.json` content for checking. – Doris Lv Feb 08 '21 at 02:00
  • Just added, thanks for looking at this! – user3787031 Feb 08 '21 at 03:01
  • Hi @user3787031, if your issue has been solved, pls [accept answers](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) on time so that people will be more glad to assist you – Jason Pan Feb 09 '21 at 07:07

2 Answers2

1

Run this command locally for installing typescript, because your code is compiled with the tsc command.

npm install -g typescript

Mostly I was following this tutorial.

Add the tsc command to package.json and add the dependencies:

"build": "tsc --project ./"
...
"devDependencies": {
    "@types/express": "^4.17.9",
    "@types/node": "^14.14.20",
    "ts-node": "^9.1.1",
    "typescript": "^4.1.3"
  },

Here is my file structure:

enter image description here

I add a empty file.ts and add this scripts to the tsconfig.jason file:

"exclude": [ "src", "wwwroot" ],
  "include": [ "file.ts" ]

Deploy through Azure Web App deployment center: enter image description here

And the app build (tsc) run successfully: enter image description here

Doris Lv
  • 3,083
  • 1
  • 5
  • 14
  • Thanks! I tried to command, but I get a series of errors: `npm ERR! 404 'typsecript@latest' is not in the npm registry.` Is this because the app service can't access the internet? I'm thinking in AWS terms where I have to grant permissions for the internet. – user3787031 Feb 08 '21 at 02:59
  • 1
    Yes, you need to access the internet. Another reason might be you need upgrade your `npm` version. – Doris Lv Feb 08 '21 at 03:08
  • I hate to ask since I feel like I'm asking to be spoonfed, but where would I handle permissions to install npm packages through the console available on the portal? I was googling for 15 minutes without anything remotely promising. Sorry :( – user3787031 Feb 08 '21 at 03:29
  • 1
    Okay, I will edit my answer step by step for deploying a web app with this command. – Doris Lv Feb 08 '21 at 05:42
  • Thanks for your help, but I think the more sane way to go about this is to just dockerize and push it out that way instead. Again thanks a ton, I appreciate it! – user3787031 Feb 08 '21 at 06:43
1

if you are deploying to Production (NODE_ENV: production), devDependencies will no longer being installed, and you need to edit your package.json and move typescript to dependencies.

Source

MajiD
  • 2,420
  • 1
  • 22
  • 32