Search code examples
node.jsherokubabeljs

Getting "Cannot find module '/app/dist'" error on deploying to Heroku


I have the following script in my package.json:

  "scripts": {
    "dev": "nodemon server --exec babel-node --presets es2015,stage-2",
    "build": "babel ./server -d ./dist",
    "start": "node ./dist",
    "heroku-postbuild": "cd react-ui/ && npm install && npm install    --only=dev --no-shrinkwrap && npm run build"
  },

On deploying to Heroku I get the following error

Error: Cannot find module '/app/dist'

On local npm run dev, npm run build, and npm run start work fine.

Where is it getting the /app folder? How to fix this?

Thanks Matloob


Solution

  • You should build your app npm run build before deploy to heroku. It will run heroku-postbuild first then start your app.