jhthorsen / mojolicious-plugin-webpack

Integrate your mojo app with webpack
13 stars 7 forks source link

Errors when trying to make a production build #14

Closed dmanto closed 2 years ago

dmanto commented 2 years ago

I've been using Mojolicious::Plugin::Webpack for more than two years now. A couple days ago I started to have some problems trying to run production builds.

Turning MOJO_WEBPACK_DEBUG on, I can see webpack complains that ../node_modules/.bin/webpack is not installed. I was able to troubleshoot it setting the MOJO_WEBPACK_BINARY to "node_modules/webpack/bin/webpack.js" on my local setup (an M1 mac), but when I try to build in my CI (github action) it keeps failing.

I prepared a repo with the webpack example on it (plus the debug option on also), that attempts to run a test based on the build-assets.t test suggested in the module's README and fails.

Hope you can take a look at the github action results, at this link

dmanto commented 2 years ago

Tried preinstalling webpack and webpack-cli before running the tests seem to be a working workaround.

Please take a look at this branch

I don't remember having to preinstall webpack before. Is this the expected behavior?

jhthorsen commented 2 years ago

Maybe webpack got an optional dependency that is not documented in https://github.com/jhthorsen/mojolicious-plugin-webpack/blob/main/lib/Mojo/Alien/webpack.pm#L31 ?

dmanto commented 2 years ago

It seems that whenever mojo tries to "npm install" a package and the NODE_ENV is "production", npm ends up cleaning all locally installed devDependence packages.

I understand the intention of the production flag is different in this case ( to tell webpack that it should prepare "production" assets), so something has to be changed I guess to allow npm install to actually install the packages.

I will PR a possible fix, please take a look and let me know what do you think about it.