【问题标题】:Deploy to Node App Azure App Service tsc not recognized as command部署到节点应用 Azure 应用服务 tsc 未被识别为命令
【发布时间】:2021-05-11 15:11:03
【问题描述】:

我正在尝试将 nodejs 应用程序部署到 Azure 应用程序服务。我做了部署它的基础知识,但它无法运行。它似乎旨在运行“node run.js”命令而不是“npm run 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"
  }
}

【问题讨论】:

  • 如果我的回答没有帮助,请发布您的package.json 内容以供检查。
  • 刚刚添加,感谢查看!
  • 您好@user3787031,如果您的问题已经解决,请及时accept answers,以便人们更乐意为您提供帮助

标签: azure-web-app-service npm-start


【解决方案1】:

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

Source

【讨论】:

    【解决方案2】:

    在本地运行此命令以安装 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) 成功运行:

    【讨论】:

    • 谢谢!我尝试命令,但出现一系列错误:npm ERR! 404 'typsecript@latest' is not in the npm registry. 这是因为应用服务无法访问互联网吗?我在考虑 AWS 术语,我必须授予互联网权限。
    • 是的,您需要访问互联网。另一个原因可能是您需要升级您的npm 版本。
    • 我不想问,因为我觉得我要求被喂饱,但是我将在哪里处理通过门户网站上可用的控制台安装 npm 包的权限?我在谷歌上搜索了 15 分钟,但没有任何希望。对不起:(
    • 好的,我将逐步编辑我的答案,以便使用此命令部署 Web 应用程序。
    • 感谢您的帮助,但我认为解决此问题的更明智的方法是 dockerize 并将其推出。再次感谢一吨,我很感激!
    猜你喜欢
    • 2018-12-13
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 2014-11-26
    • 2017-01-07
    • 1970-01-01
    相关资源
    最近更新 更多