简体   繁体   中英

Deploying Node.js typescript application to heroku

I'm stuck deploying a Node.js typescript application to Heroku. It would be great if you could help me out.

If I run npm run build , npm run start or npm run start:dev everything seems to work just fine. When I try to deploy my app to Heroku using git push heroku main I get the following error:

Heroku部署错误

I checked every import in my application, but couldn't find a single one being incorrect or missing in "dependencies" in my package.json .

I am truely clueless about the solution, but I figured some extra information might be useful:

file structure:

文件结构

procfile:

web: node build/server.js

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",                     
    "module": "commonjs",                  
    "lib": ["es6"],                     
    "allowJs": true,
    "outDir": "./build",                          
    "rootDir": "./src",
    "strict": true,         
    "noImplicitAny": true,
    "esModuleInterop": true,
    "resolveJsonModule": true
  }
}

scripts:

  "scripts": {
    "start": "set NODE_ENV=production&& npm run build && node build/server.js",
    "start:dev": "set NODE_ENV=development&& npm run build && nodemon --ext \".ts,.js\" --watch \"./src\" --exec \"ts-node ./src/server.ts\"",
    "start:local": "set NODE_ENV=local&& nodemon",
    "test": "ts-mocha -p ./tsconfig.json ./src/**/*.spec.ts",
    "coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" npm run test",
    "build": "rimraf ./build && tsc"
  }

Seems like github didn't change my filenames. While I had the right filenames locally, in github they were all wrongly cased. I had to remove the projects gitfile, change the filenames and forcepush to my git repo after I initialized a new git file in my project. Thanks to @jonrsharpe I noticed how important casing can be and how we should watch carefully if everything is written the way it should be. If someone else came across the same issue: Pay attention to namecasing -> local filenames must match the github filenames !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM