Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku can't find ts-node

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! [email protected] 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 [email protected] 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?

like image 609
Ankit singh kushwah Avatar asked Mar 18 '26 05:03

Ankit singh kushwah


1 Answers

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.

like image 134
Chris Avatar answered Mar 19 '26 18:03

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!