问题描述
我正在尝试将 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"
}
}
解决方法
在本地运行这个命令来安装 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" ]