Search code examples
node.jstypescriptstronglooploopback4

Loopback 4 deployment in heroku, lb-tsc not found error


I'm trying to deploy a loopback 4 app into heroku. But after publishing it npm-start command not working in heroku console. its throwing sh: 1: lb-tsc not found. package.json is as follows

"devDependencies": {
"@loopback/build": "^3.0.0",
"@loopback/eslint-config": "^5.0.0",
"@loopback/testlab": "^1.10.0",
"@types/node": "^10.17.6",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"eslint": "^6.7.2",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-eslint-plugin": "^2.1.0",
"eslint-plugin-mocha": "^6.2.2",
"source-map-support": "^0.5.16",
"typescript": "~3.7.3"},
"scripts": {
    "build": "lb-tsc",
    "build:watch": "lb-tsc --watch",
    "clean": "lb-clean dist *.tsbuildinfo",
     .......
    "lb-tsc": "lb-tsc",
    "postinstall": "npm run lb-tsc"
  }

Solution

  • When heroku runs node application the value of process.env.NODE_ENV is "production" you may check it from heroku terminal bash by typing node and then process.env And this means that dev dependencies are not resolved.

    Below steps work fine to me

    1. Open package.json file copy all from dev dependeny section and paste it to dependency section in package.json
    2. git add . then git commit and then git push heroku master

    Another Solution: After pushing files to heroku using git push heroku master go to heroku terminal from https://dashboard.heroku.com/ and start console and then run command node dist/index.js so this command will start loopBack application make sure dist folder is available.