【问题标题】:Heroku can't find ts-nodeHeroku 找不到 ts 节点
【发布时间】:2019-12-23 21:14:36
【问题描述】:

我在多人游戏中使用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

【问题讨论】:

    标签: typescript heroku


    【解决方案1】:

    ts-node 在您的devDependencies 中列出,但they aren't available at runtime out of the box

    默认情况下,Heroku 将安装 package.json 下的所有依赖项 dependenciesdevDependencies

    运行安装后,build steps Heroku 将在部署应用程序之前剥离devDependencies 下声明的包。

    如果您在运行时需要ts-node,我建议您将其移至您的dependencies

    其他解决方案是仅在构建时使用它(我不确定 ts-node 是否可能,但它可能涉及将您的 TypeScript 编译为 JavaScript)或 configuring Heroku not to strip your devDependencies。我强烈建议不要使用最后一个选项 - devDependencies 在生产中不应该是必需的。

    【讨论】:

      猜你喜欢
      • 2019-11-07
      • 2012-10-08
      • 2012-08-23
      • 2021-11-16
      • 2018-11-27
      • 2018-02-28
      • 2017-10-16
      • 2014-06-12
      • 1970-01-01
      相关资源
      最近更新 更多