Error: Cannot find module when deploying to heroku
Problem
Using latest next.js relase and a simple hello world index page with 0 dependencies fails to run on heroku with the following error: [code block]
Error Output
Error: Cannot find module '/tmp/build_xxx/node_modules/babel-runtime/helpers/inherits'
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Module Not Found Error on Heroku Deployment
The error occurs because the Babel runtime is not included in the dependencies of the project. When deploying to Heroku, the build process does not find the 'babel-runtime' module, which is required for transpiling the code. This can happen if the module is only installed locally and not listed in the package.json file, or if there are issues with the build process that prevent it from being installed correctly.
Awaiting Verification
Be the first to verify this fix
- 1
Add babel-runtime to dependencies
Ensure that 'babel-runtime' is included in your project's dependencies. This will allow Heroku to install it during the build process.
bashnpm install --save babel-runtime - 2
Check package.json for correct dependencies
Open your package.json file and verify that 'babel-runtime' is listed under 'dependencies'. If it's missing, manually add it or run the install command again.
json{ "dependencies": { "babel-runtime": "^6.26.0" } } - 3
Clear Heroku cache
Sometimes Heroku caches previous builds. Clear the cache to ensure that the latest dependencies are installed correctly. Use the Heroku CLI to run the following command.
bashheroku repo:purge_cache -a your-app-name - 4
Redeploy the application
After making the changes and clearing the cache, redeploy your application to Heroku to apply the updates.
bashgit push heroku main
Validation
After redeploying the application, check the Heroku logs using 'heroku logs --tail' to confirm that the error no longer appears and that the application starts successfully.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep