提问人:idk 提问时间:11/13/2023 更新时间:11/15/2023 访问量:22
TSC:尽管尝试了所有方法,但在 Heroku 中未发现错误
tsc: not found error in heroku despite trying everything
问:
我正在尝试将一个简单的 nodejs 应用程序部署到 heroku,但出现上述错误。尝试根据此处的可用答案解决它,但似乎没有任何效果。这是我已经尝试过的:
- 在测功机上安装打字稿构建包
heroku buildpacks: heroku/nodejs zidizei/typescript
- 我的package.json在devDependencies中有typescript,scripts在build参数中有tsc
...
"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"
}
...
- 我的tsconfig.json也与我在这里看到的答案非常吻合
{
"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
用尽了所有关于我可能做错了什么的想法,并希望从中得到启发。我还应该尝试其他事情吗?
提前致谢!
答:
1赞
idk
11/15/2023
#1
通过将 tsc 放入 build 而不是 postinstall 来让它工作,因为 heroku 调用 npm start build。在安装后阶段,devDependencies 似乎不再可访问。
...
"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"
}
评论