Search code examples
node.jstypescriptherokudevelopment-environment

Cannot find module '/app/dist/bin/www.js'


So I am having this error on Heroku. I just woke up this morning and found it after adding a new feature. It says my www.js file is not found. This file is not on GitHub. I am writing typescript so I'm guessing Heroku will build my project and create a "./dist" folder which will include the /bin/www.js file. The application was working before and still works locally. The application still builds successfully. I have tried adding a Procfile and also used a preinstall script but nothing seems to work. Is it possible to know if the "./dist" folder was successfully created?

Error on Heroku:

enter image description here

Folder Structure:

enter image description here

Scripts:

"scripts": {
    "test": "SET NODE_ENV=test&& mocha --exit -r ts-node/register tests/**/*.ts",
    "dev": "nodemon src/bin/www.ts",
    "start": "nodemon dist/bin/www.js",
    "build": "tsc -p .",
    "lint": "eslint . --ext .ts",
    "precommit": "npm run lint&& npm test",
    "preinstall": "npm run build"
  }`

The Procfile just has: web: npm start


Solution

  • I found the problem. Apparently, the new build created another www.js file in "dist/src/bin/www.js" and deleted "dist/bin/www.js" on Heroku. I have no idea why this happened. So I changed my start script to "nodemon dist/src/bin/www.js".