Debugging silently failing compilation aka Webpacker can’t find application.js in public/packs/manifest.json

Webpacker can pretend everything went smooth with the compilation… until one loads a page with javascript_pack_tag helper.

I was deploying a new version of one application that included latest pre-release of Webpacker to production and it failed with:

After investigating the .../app/public/packs path on the server I found out there no packs generated whatsoever! I checked that locally I am able to generate the assets just fine both with:

or:

However on the server those commands did nothing. No errors. They even happily printed:

After that I went on a typical programmer journey to find out what might be the issue. I went to google. Webpacker can’t find application.js was indeed a discovered error and yielded various Webpacker issues. Unfortunately nothing seemed like a fix for my broken deploy and I went to read the source code. I looked for a place where Webpacker happily prints out that compilation was a success.

This is the method:

As you can see it just runs webpack from the correct path and checks for the command standard error output and exit code.

So what if I run bin/webpack on the server?

I am missing Webpack CLI which I of course have as a development dependency locally so it never installed on the production server during build (and gave me a headache).

Resolution: don’t put webpack-cli package only as a dev dependency if you need to do the compilation on the server.

If you by any chance come here because of Webpack error and this is not your error make sure to check the troubleshooting guide.

Leave a comment

Your email address will not be published. Required fields are marked *