gpt4 book ai didi

typescript - Heroku 找不到 ts-node

转载 作者:行者123 更新时间:2023-12-04 00:25:13 26 4
gpt4 key购买 nike

我正在使用 Colyseus对于我的多人游戏。该框架生成了一个 typescript 服务器,我试图将其部署到 Heroku。我的日志中出现以下错误:

2019-08-18T09:45:55.362304+00:00 app[web.1]: npm ERR! syscall spawn
2019-08-18T09:45:55.363375+00:00 app[web.1]: npm ERR! my-app@1.0.0 start: `ts-node index.ts`
2019-08-18T09:45:55.363477+00:00 app[web.1]: npm ERR! spawn ENOENT
2019-08-18T09:45:55.363677+00:00 app[web.1]: npm ERR!
2019-08-18T09:45:55.363800+00:00 app[web.1]: npm ERR! Failed at the my-app@1.0.0 start script.
2019-08-18T09:45:55.363912+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-08-18T09:45:55.373038+00:00 app[web.1]:
2019-08-18T09:45:55.373380+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-08-18T09:45:55.373520+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-08-18T09_45_55_365Z-debug.log

我的 package.json :
{
"name": "my-app",
"version": "1.0.0",
"description": "npm init template for bootstraping an empty Colyseus project",
"main": "lib/index.js",
"scripts": {
"start": "ts-node index.ts",
"loadtest": "colyseus-loadtest loadtest/example.ts --room my_room --numClients 2",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "UNLICENSED",
"bugs": {
"url": "https://github.com/colyseus/create-colyseus/issues"
},
"homepage": "https://github.com/colyseus/create-colyseus#readme",
"devDependencies": {
"@colyseus/loadtest": "^0.10.1",
"@types/express": "^4.16.1",
"ts-loader": "^5.3.3",
"ts-node": "^8.1.0",
"typescript": "^3.4.5"
},
"dependencies": {
"@colyseus/monitor": "^0.10.0",
"@colyseus/social": "^0.10.2",
"colyseus": "^0.10.7",
"express": "^4.16.4",
"express-jwt": "^5.3.1"
}
}

这是 tsconfig.json :
{
"compilerOptions": {
"outDir": "lib",
"target": "es6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true
}
}

为什么 Heroku 找不到 ts-node ?

最佳答案

ts-node已在您的 devDependencies 中列出但是 they aren't available at runtime out of the box :

By default, Heroku will install all dependencies listed in package.json under dependencies and devDependencies.

After running the installation and build steps Heroku will strip out the packages declared under devDependencies before deploying the application.


如果您需要 ts-node在运行时,我建议将其移至您的 dependencies .
其他解决方案是仅在构建时使用它(我不确定这是否适用于 ts-node,但它可能涉及将您的 TypeScript 编译为 JavaScript)或 configuring Heroku not to strip your devDependencies .我强烈建议不要使用最后一个选项— devDependencies生产中应该不需要。

关于typescript - Heroku 找不到 ts-node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57543386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com