NodeJS tsc:在heroku中没有发现错误,尽管尝试了所有方法

ecfdbz9o  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(128)

我试图部署一个简单的nodejs应用到heroku,但得到上述错误。尝试解决它的基础上可用的答案在这里,但似乎没有工作。这是我已经尝试过:
1.已在dyno heroku buildpacks: heroku/nodejs zidizei/typescript上安装typescript buildpack
1.我的package.json在开发参数中有typescript,脚本在构建参数中有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"
  }
...

字符串
1.我的tslog.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
       
       > [email protected] postinstall
       > npm run build
       
       
       > [email protected] 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 [email protected]` 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


用尽所有的想法,我可能做错了什么,并期待得到启发,在相同的。任何其他的事情,我应该尝试?
提前感谢!

3okqufwl

3okqufwl1#

通过将tsc放入build而不是postinstall来使它工作,就像heroku调用npm start build一样。在postinstall阶段,似乎不再可以访问开发环境。

...
  "scripts": {
    "start": "node build/server.js",
    "build": "tsc",
    "dev": "nodemon server.ts",
    "start:server": "ts-node server.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  }

字符串

相关问题