9

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 :(

6
  • 4
    Execute npm install postcss --save-dev. It should resolve your issues. Commented Apr 1, 2018 at 4:39
  • I install postcss, but error continues. Commented Apr 1, 2018 at 14:16
  • Seems strange to me, sass-loader only require node-sass to be installed as peerDependency. You don't need postcss to use sass-loader. Anyway, try to install both postcss and postcss-loader with npm install --save-dev postcss postcss-loader, and try to add {loader: "postcss-loader"} in between your sass-loader and css-loader. Commented Apr 2, 2018 at 1:56
  • I try to execute my project in a linux machine and I don't have any problems. For some reason in my windows machine I always get this error. I verify in my node_modules/postcss only have these files: node_modules and package.info. It is like modules not installed correctly. Commented Apr 3, 2018 at 2:16
  • 1
    On Windows try to delete your node_modules && package-lock.json and then run npm install to re-install all packages. Commented Apr 5, 2018 at 22:55

4 Answers 4

22

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]
Sign up to request clarification or add additional context in comments.

Comments

5

Use the following steps

Delete package-lock.json

Delete node_modules

Run npm install

Comments

3

In my case problem was solved by delete package.lock.

1 Comment

This can solve our problem. this should be correct answer.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.