部署到 Node App Azure App Service tsc 未被识别为命令

Deploy to Node App Azure App Service tsc not recognized as command

我正在尝试将 nodejs 应用部署到 Azure 应用服务上。我完成了部署它的基础知识,但它无法 运行。它似乎是为 运行“node run.js”命令而不是“npm 运行 start”而设计的。

我正在控制台中玩游戏,如果我尝试手动 运行 npm run start,我会遇到一系列与构建相关的错误。基本上:

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

我想知道这里是否有关于如何将 tsc(和其他)添加到路径的真正明显的东西。我必须承认,我并不是特别精通 Azure 或 Node 的使用。任何帮助将不胜感激!谢谢!

这是 package.json 文件:

{
  "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"
  }
}

运行这个命令是本地安装typescript的,因为你的代码是用tsc命令编译的。

npm install -g typescript

我主要关注这个 tutorial

将tsc命令添加到package.json并添加依赖项:

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

这是我的文件结构:

我添加一个空 file.ts 并将此脚本添加到 tsconfig.jason 文件:

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

通过 Azure Web App 部署中心部署:

应用构建 (tsc) 运行 成功:

如果您要部署到 Production(NODE_ENV:生产),将不再安装 devDependencies,您需要编辑 package.json 并移动 typescriptdependencies.

Source