3

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"
  }

5 Answers5

3

Creating a Procfile in the root of the project containing web: node . fixed this for me. Without it, Heroku will default to starting the app by calling npm run which tries to run the build process, and since @loopback/build is set up as a dev dependency by default, this results in the lb-tsc not found error.

Tom Monks
  • 51
  • 1
2

I have tried many solutions and it works when I do the following things :

Make sure heroku has a nodeJs builpack running in your terminal

heroku buildpacks:set heroku/nodejs

Then, create a Procfile to the root of your project and add :

web: node index.js

Finally add a heroku-postbuild script :

"heroku-postbuild": "npm run build"

Hope it helps !

rcarette
  • 111
  • 2
  • 10
2

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.

Neeraj Negi
  • 704
  • 8
  • 5
1

Try to install it in the command line:
npm i -g @loopback/cli npm i -g @loopback/build

I'm using it in macos from command line.

Vitaliy
  • 416
  • 6
  • 9
1

I read somewhere to replace web: slc run with web: node . in Procfile, and it seems to be working in Heroku! I do see the explorer and can use all the endpoints.

I mention this also in this Github issue: https://github.com/strongloop/loopback.io/issues/810

user2078023
  • 1,137
  • 1
  • 10
  • 28