Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack: Module build failed: Error: Cannot find module 'postcss'

I am trying to integrate my webpack project with sass-loader, but I am get this error:

 Module build failed: Error: Cannot find module 'postcss'

I already installed postcss and postcss-loader with command:

 npm install postcss postcss-loader --save-dev

After install, I continue to get the same error message. I test integrate my project only with css-loader and the same error occurs. I think postcss is a dependency of the css-loader.

In my webpack.config.js I use this configuration in my module.rules:

 {
    test: /\.scss$/,
    use: [{
          loader: "style-loader" // creates style nodes from JS strings
      }, {
          loader: "css-loader" // translates CSS into CommonJS
      }, {
          loader: "sass-loader" // compiles Sass to CSS
      }
    ]
  }

I installed all this loaders and node-sass, I don't know what I am doing wrong :(

like image 641
Elton Serra Avatar asked Apr 01 '18 04:04

Elton Serra


2 Answers

I had this error when using autoprefixer with postcss through postcss-cli. I solved it by rolling postcss back to version 8.1.0 (current version is 8.1.1 at time of writing). This can be easily done by running the below command in your terminal.

npm i [email protected]
like image 179
Joe Herbert Avatar answered Sep 17 '22 02:09

Joe Herbert


Upgrading postcss-cli to the new version 9.0.1 fixed it for me.

like image 29
kmonsoor Avatar answered Sep 21 '22 02:09

kmonsoor