Heroku can't find ts-node

大兔子大兔子 提交于 2020-06-26 05:57:10

问题


I am using Colyseus for my multiplayer game. The framework generated a typescript server which I tried to deploy to Heroku. I am getting the following error in my logs:

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

My 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"
  }
}

This is the tsconfig.json:

{
  "compilerOptions": {
    "outDir": "lib",
    "target": "es6",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "experimentalDecorators": true
  }
}

Why can't Heroku find ts-node?


回答1:


ts-node is listed in your devDependencies but 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.

If you need ts-node at runtime I suggest moving it to your dependencies.

Other solutions would be to use it only at build time (I'm not sure if this is possible with ts-node but it would probably involve compiling your TypeScript to JavaScript) or configuring Heroku not to strip your devDependencies. I strongly advise against this last option—devDependencies shouldn't be required in production.



来源:https://stackoverflow.com/questions/57543386/heroku-cant-find-ts-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!