我在多人游戏中使用Colyseus。该框架生成了一个打字稿服务器,我尝试将其部署到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
?
答案 0 :(得分:1)
ts-node
在您的devDependencies
中列出,但在they aren't available at runtime out of the box中:
默认情况下,Heroku将安装
package.json
和dependencies
下devDependencies
中列出的所有依赖项。运行安装后,build steps在部署应用程序之前,Heroku将清除
devDependencies
下声明的软件包。
如果您在运行时需要ts-node
,建议将其移至dependencies
。
其他解决方案是仅在构建时使用它(我不确定ts-node
是否可行,但可能涉及将TypeScript编译为JavaScript)或configuring Heroku not to strip your devDependencies
。我强烈建议不要使用最后一个选项-devDependencies
在生产中不需要。