Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

typescript - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...