Laravel Mix / Node JS versions and webpack fun Laravel Mix / Node JS versions and webpack fun

February 15, 2022

laravel

Spent most of the morning struggling to get npm run production working on my new machine. The problem was a combination of things:

  • Node JS version
  • Laravel Mix version
  • Tailwind CSS
  • Webpack

Solutions I tried:

npm install laravel-mix-purgecss@6.0.0
npm install --save-dev sass-loader@7.1.0
npm install node-sass@v4
npm install --save-dev cross-env
npm install postcss-loader@~3.0.0 --save-dev
npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@\^7 autoprefixer@\^9 --force

Downgrade Node to version 12, then deleted the entire node_modules directory and reinstalled with the original package.json file.

Then fixed more errors until it worked.

This is now my package.json file

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@tailwindcss/typography": "^0.4.0",
        "axios": "^0.19",
        "cross-env": "^7.0.3",
        "laravel-mix": "^5.0.1",
        "laravel-mix-purgecss": "^5.0.0",
        "lodash": "^4.17.13",
        "postcss-loader": "~3.0.0",
        "resolve-url-loader": "^3.1.0",
        "sass": "^1.48.0",
        "sass-loader": "^8.0.0",
        "vue-template-compiler": "^2.6.14"
    },
    "dependencies": {
        "@tailwindcss/forms": "^0.3.4",
        "autoprefixer": "^9.8.8",
        "boundingbox": "^0.1.2",
        "escape-html": "^1.0.3",
        "leaflet": "^1.7.1",
        "overpass-frontend": "^2.7.0",
        "overpass-layer": "^3.1.0",
        "postcss": "^7.0.39",
        "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.17",
        "yaml": "^1.9.2"
    }
}

Once I got this all working, my ansible script then reinstalled v.14 of Node JS :) so now updating the ansible scripts to install v.12.

Most of a day of experimenting with the behemoth that is the world of Node JS :)

Edit 28th Feb 2022

I ran into this same problem again with another site. I added webpack 4 to the dependencies

        "webpack": "^4.00.0"

and did a hard reinstall of all the node modules!

rm -rf node_modules
rm package-lock.json
npm cache clear --force
npm install

If you would like to contact me with this form on londinium.com, ilminster.net or via Twitter @andylondon