我在多人游戏中使用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
Run Code Online (Sandbox Code Playgroud)
我的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"
}
}
Run Code Online (Sandbox Code Playgroud)
这是tsconfig.json
:
{
"compilerOptions": {
"outDir": "lib",
"target": "es6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true
}
}
Run Code Online (Sandbox Code Playgroud)
为什么 Heroku 找不到ts-node
?
ts-node
列在您的devDependencies
但它们在运行时开箱即用:
默认情况下,Heroku 将安装
package.json
在dependencies
和 下列出的所有依赖项devDependencies
。在运行安装和构建步骤之后, Heroku 将
devDependencies
在部署应用程序之前去掉在下面声明的包。
如果您ts-node
在运行时需要,我建议将其移至您的dependencies
.
其他解决方案是仅在构建时使用它(我不确定这是否可行,ts-node
但它可能涉及将您的 TypeScript 编译为 JavaScript)或配置 Heroku 不剥离您的devDependencies
. 我强烈建议不要使用最后一个选项——devDependencies
在生产中不应该需要。
归档时间: |
|
查看次数: |
1453 次 |
最近记录: |