我正在尝试将一个简单的nodejs应用程序部署到heroku,但出现上述错误。尝试根据此处的可用答案解决该问题,但似乎没有任何效果。这是我已经尝试过的:
heroku buildpacks: heroku/nodejs zidizei/typescript
...
"main": "index.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.1",
"rimraf": "^5.0.5",
},
"devDependencies": {
"@types/express": "^4.17.14",
"@types/node": "^18.11.0"
"nodemon": "^2.0.19",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"scripts": {
"start": "node build/server.js",
"postinstall": "tsc",
"dev": "nodemon server.ts",
"start:server": "ts-node server.ts",
"test": "echo \"Error: no test specified\" && exit 1"
}
...
{
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
},
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"rootDir": "./",
"outDir": "./build",
"strict": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"moduleResolution":"node",
"skipLibCheck": true
},
"files": [ "./utils/index.d.ts" ]
}
我在构建步骤中遇到错误:
-----> TypeScript app detected
-----> Creating build environment
-----> Installing development dependencies
Installing development node modules (npm)
npm WARN invalid config only="dev" set in command line options
npm WARN invalid config Must be one of: null, prod, production
> [email protected] postinstall
> npm run build
> [email protected] build
> tsc
sh: 1: tsc: not found
npm notice
npm notice New minor version of npm available! 10.1.0 -> 10.2.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.2.3>
npm notice Run `npm install -g [email protected]` to update!
npm notice
npm ERR! code 127
npm ERR! path /tmp/build_5663ceba
npm ERR! command failed
npm ERR! command sh -c npm run build
用尽所有关于我可能做错的事情的想法,并寻求同样的启发。还有其他我应该尝试的事情吗?
提前致谢!
通过将 tsc 放入 build 而不是 postinstall 来使其工作,就像 Heroku 调用 npm start build 一样。在安装后阶段,似乎不再可以访问 devDependency。
...
"scripts": {
"start": "node build/server.js",
"build": "tsc",
"dev": "nodemon server.ts",
"start:server": "ts-node server.ts",
"test": "echo \"Error: no test specified\" && exit 1"
}