You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku部署Node.js应用遇tsc: not found错误,多种方案尝试无效

Heroku部署Node.js(TypeScript)应用时遇到tsc: not found错误

部署一个简单的Node.js(TypeScript)应用到Heroku时,触发tsc: not found错误,以下是已尝试但无效的方案:

已尝试的无效方案

  • 为dyno安装TypeScript buildpack:
    heroku buildpacks: heroku/nodejs zidizei/typescript
    
  • 在package.json中已将typescript加入devDependencies,且scripts的build命令包含tsc,配置片段如下:
    ...
    "main": "index.js",
    "dependencies": {
      "cors": "^2.8.5",
      "express": "^4.18.1",
      "rimraf": "^5.0.5",
    },
    "devDependencies": {
      "@types/express": "^4.17.14",
      "@types/node": "^18.11.0"
      "nodemon": "^2.0.19",
      "ts-node": "^10.9.1",
      "typescript": "^4.7.4"
    },
    "scripts": {
      "start": "node build/server.js",
      "postinstall": "tsc",
      "dev": "nodemon server.ts",
      "start:server": "ts-node server.ts",
      "test": "echo \"Error: no test specified\" && exit 1"
    }
    ...
    
  • tsconfig.json配置与参考示例一致:
    {
       "ts-node": {
       "compilerOptions": {
         "module": "commonjs"
       }
     },
     "compilerOptions": {
       "module": "commonjs",
       "esModuleInterop": true,
       "target": "es6",
       "rootDir": "./",
       "outDir": "./build",
       "strict": true,
       "experimentalDecorators": true,
       "emitDecoratorMetadata": true,
       "strictPropertyInitialization": false,
       "moduleResolution":"node",
       "skipLibCheck": true
     },
     "files": [ "./utils/index.d.ts" ]
    }
    

构建时的错误信息

-----> TypeScript app detected
-----> Creating build environment
-----> Installing development dependencies
       Installing development node modules (npm)
       npm WARN invalid config only="dev" set in command line options
       npm WARN invalid config Must be one of: null, prod, production
       
       > rmr@1.0.0 postinstall
       > npm run build
       
       
       > rmr@1.0.0 build
       > tsc
       
       sh: 1: tsc: not found
       npm notice
       npm notice New minor version of npm available! 10.1.0 -> 10.2.3
       npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.2.3>
       npm notice Run `npm install -g npm@10.2.3` to update!
       npm notice
       npm ERR! code 127
       npm ERR! path /tmp/build_5663ceba
       npm ERR! command failed
       npm ERR! command sh -c npm run build

寻求其他解决方案

已用尽现有思路,希望得到启发,请问还有哪些可尝试的方案?

内容的提问来源于stack exchange,提问作者idk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 08:10:00