postcss-import: Throws "Error: PostCSS plugin postcss-import requires PostCSS 8" even when PostCSS 8 is installed

PS F:\code\cloverleaf\web> npm view postcss version
8.1.2
PS F:\code\cloverleaf\web> npm run build

> cloverleaf-web@1.0.0 build F:\code\cloverleaf\web
> cross-env NODE_ENV=production node --no-deprecation config/webpack/config.js

Translations up to date
Processing translations
Finished processing translations
Build completed in 8.733s

assets by status 118 KiB [cached] 1 asset
runtime modules 1.1 KiB 8 modules
orphan modules 1.07 KiB [orphan] 1 module
modules by path ./node_modules/ 211 KiB 26 modules
modules by path ./src/ 20.8 KiB
  ./src/main.js 20.7 KiB [built] [code generated]
  ./src/style.scss 39 bytes [built] [code generated] [1 error]
modules by path ./data/*.json 2.64 KiB
  ./data/logos.json 1.53 KiB [built] [code generated]
  ./data/themes.json 1.11 KiB [built] [code generated]
./langs/langs.json 159 bytes [built] [code generated]
crypto (ignored) 15 bytes [optional] [built] [code generated]

ERROR in ./src/style.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/src/index.js):
Error: PostCSS plugin postcss-import requires PostCSS 8.
Migration guide for end-users:
https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users
    at Processor.normalize (F:\code\cloverleaf\web\node_modules\postcss-loader\node_modules\postcss\lib\processor.js:153:15)
    at new Processor (F:\code\cloverleaf\web\node_modules\postcss-loader\node_modules\postcss\lib\processor.js:56:25)
    at postcss (F:\code\cloverleaf\web\node_modules\postcss-loader\node_modules\postcss\lib\postcss.js:55:10)
    at F:\code\cloverleaf\web\node_modules\postcss-loader\src\index.js:140:12
    at processResult (F:\code\cloverleaf\web\node_modules\webpack\lib\NormalModule.js:576:19)
    at F:\code\cloverleaf\web\node_modules\webpack\lib\NormalModule.js:669:5
    at F:\code\cloverleaf\web\node_modules\loader-runner\lib\LoaderRunner.js:397:11
    at F:\code\cloverleaf\web\node_modules\loader-runner\lib\LoaderRunner.js:252:18
    at context.callback (F:\code\cloverleaf\web\node_modules\loader-runner\lib\LoaderRunner.js:124:13)
    at F:\code\cloverleaf\web\node_modules\postcss-loader\src\index.js:208:9
 @ ./src/main.js 19:0-22

1 ERROR in child compilations
webpack 5.1.3 compiled with 2 errors in 8733 ms

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 50
  • Comments: 26

Commits related to this issue

Most upvoted comments

We ended up pinning postcss-import at 12.x while keeping up-to-date with postcss on the latest branch:

    "postcss": "^8.1.9",
    "postcss-import": "12.0.1",

Closing, since no reduced test case has presented itself.

In my case it was a bunch of modules requesting postcss@7 as dependency. See yarn why postcss Since the postcss API from 7 to 8 should not differ much I just resolved the issue by adding postcss@8 to the resolutions in package.json

 "resolutions": {
    "postcss": "8"
  }

I’m not using any post css and I’m getting this when using mini-css-extract-plugin

Just ran into this myself today, the culprit being Storybook that references an older postcss-loader that in turn imported an older postcss-import (https://github.com/storybookjs/storybook/blob/next/lib/core/package.json#L112)

I think in my case it may be something to do with vuepress calling an older version of postcss under the hood…

Thanks @karladler at https://github.com/postcss/postcss-import/issues/435#issuecomment-939991463 for the yarn solution.

In my case, I am using npm.

I didn’t use postcss directly. However, when Renovate does lock file maintenance of package-lock.json, it throws error

PostCSS plugin postcss-discard-comments requires PostCSS 8

when I build my web app.

Because some dependencies of dependencies are using PostCSS 7

Adding overrides:

"overrides": {
   "postcss": "8.4.19"
}

in package.json which is similar to resolutions from yarn.

Then run npm install. Next time, when Renovate does lock file maintenance of package-lock.json, it will use PostCSS 8 instead of PostCSS 7.

Note

  1. overrides got supported since npm 8.3.0.
  2. peerDependencies does not work for me in this Renovate lock file maintenance case. Some are still using PostCSS 7.

We ended up pinning postcss-import at 12.x while keeping up-to-date with postcss on the latest branch:

    "postcss": "^8.1.9",
    "postcss-import": "12.0.1",

I had trouble with rollup-plugin-postcss. It worked, just run yarn add -D postcss@8.1.9 and yarn add -D postcss-loader@4.1.0.

I has this error happen to me while I only had postcss-cli in my explicit dependencies. Adding postcss as an explicit dependency fixed it.

On my file package.json I configured this:

"dependencies": {
   "postcss-import": "^14.1.0",
   "postcss-loader": "^4.3.0",
   "postcss-mixins": "^9.0.2",
   "postcss-nesting": "^10.1.4",
 },
 "devDependencies": {
   "postcss": "^8.4.18",
 },
 "peerDependencies": {
   "postcss": "^8.4.18"
 },

I noticed the file package-lock.json had a section for an specific package I use (@ckeditor/ckeditor5-dev-utils) and it was requiring specific versions installed:

"@ckeditor/ckeditor5-dev-utils": {
      "version": "31.1.5",
      "resolved": "https://registry.npmjs.org/@ckeditor/ckeditor5-dev-utils/-/ckeditor5-dev-utils-31.1.5.tgz",
      "integrity": "sha512-0hBxhrA0aLkLHxmC3Pc9ruebELeWtOFqK599Lo304CdA3R9UOIYwHnNCXw8NTwnxAtPuvsqAATwbHGEV/tpy9g==",
      "requires": {
           
        "postcss": "^8.4.12",
        "postcss-import": "^14.1.0",
        "postcss-loader": "^4.3.0",
        "postcss-mixins": "^9.0.2",
        "postcss-nesting": "^10.1.4",
           
      },
      "dependencies": {
    [rest of the list of dependences].
      }
    },

Just downgrade to “postcss-loader”: “^4.1.0”

Thanks @karladler. Elegant and effective solution. Afterwards I just had to refresh running yarn and the error was gone.