【问题标题】:Error: PostCSS plugin autoprefixer requires PostCSS 8. Update PostCSS or downgrade this plugin错误:PostCSS 插件 autoprefixer 需要 PostCSS 8。更新 PostCSS 或降级此插件
【发布时间】:2021-01-11 08:53:45
【问题描述】:

每当我运行 npm start 时,我都会收到此错误。 我尝试了几个修复,但没有一个对我有用。我尝试将 autoprefixer 的版本更改为 9.8.6,但没有成功。 请帮我解决这个问题

这是我的 package.json

{
  "name": "reactgallery",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3"
  },
  "scripts": {
    "start": "npm run watch:css && react-scripts start",
    "build": "npm run build:css && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "build:css": "postcss src/assets/tailwind.css -o src/assets/main.css",
    "watch:css": "postcss src/assets/tailwind.css -o src/assets/main.css"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^9.8.6",
    "postcss-cli": "^7.1.2",
    "tailwindcss": "^1.8.10"
  }
}

【问题讨论】:

    标签: reactjs npm postcss


    【解决方案1】:

    对此我不确定,但您可以尝试将 postcss 作为依赖项安装吗?

    npm i postcss
    

    【讨论】:

    • 感谢您的回复。我会试试的。
    • 这对我有用,并且 CSS 已正确缩小,非常感谢
    【解决方案2】:

    快速修复

    将您的自动前缀器降级到版本 9,使用

    “自动前缀”:“^9.0.0”

    在您的开发依赖项中。

    更多详情

    PostCSS 已更新到版本 8,但是,PostCSS CLI 尚未更新以处理使用新 PostCSS 8+ API 的 PostCSS 插件。 Autoprefixer 从版本 10 开始使用新的 PostCSS 8 API。

    这记录在PostCSS GitHub 页面的已知问题下。

    一旦 PostCSS CLI 更新以处理使用新 PostCSS 8+ API 的插件,这可能不会成为问题。但在那之前,您可能需要降级一些 PostCSS 插件以避免错误。

    【讨论】:

    • 感谢您的回复。这对我不起作用。我仍然收到此错误。错误:PostCSS 插件自动前缀需要 PostCSS 8。更新 PostCSS 或降级此插件。
    • @RishiPurwar 你删除了你的 node_modules 文件夹并运行了npm installyarn install 吗?
    • 更新:postcss-cli v8 支持 postcss v8
    • 是的,postcss-cli v8 目前支持 postcss v8
    • "@tailwindcss/postcss7-compat": "^2.2.4", "autoprefixer": "^9.8.6", "postcss": "^7.0.35",使用这些组合。它应该工作..
    【解决方案3】:

    好的,对我来说已修复删除 package-lock.json 并安装:

    "tailwindcss": "^1.8.10"
    "postcss-cli": "^7.1.0"
    "autoprefixer": "^9.7.5"
    

    【讨论】:

    • 删除包锁对我有用。但我正在使用 ^9.8.5。
    【解决方案4】:

    以下组合自 2020 年 10 月起有效

      ...
      "dependencies": {
        "autoprefixer": "^9.8.6",
        "postcss-cli": "^8.1.0",
        "tailwindcss": "^1.9.2"
      }
    

    【讨论】:

      【解决方案5】:

      基于文档link 放弃了对旧 NodeJS 的一些支持,您必须手动升级包。以我为例,基于 webpack 的项目只需要更新这些依赖项:

        "dependencies": {
          "autoprefixer": "^10.0.2",
          "postcss": "^8.1.7",
          "postcss-loader": "^4.0.4"
        }
      

      所以你不需要降级 autoprefixer :)

      【讨论】:

      • 为我工作 - 无法通过终端添加“post-css”包,但在手动将行添加到 package.json 并重新安装一切都很好。
      • 耶!谢谢!这实际上奏效了。多年来,这一直困扰着我。这适用于很棒的 gulp-postcss 插件:) 认为答案就像“只需手动安装软件包”一样简单
      【解决方案6】:

      对于 Next.js 10,您只需要这样做

      npm install tailwindcss@latest postcss@latest autoprefixer@latest
      

      来源This issue here

      【讨论】:

        【解决方案7】:

        如果您遇到此问题并且使用的是 Tailwind CSS v2,请尝试此操作

        npm uninstall tailwindcss postcss autoprefixer
        npm install tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
        
        

        来源:https://tailwindcss.com/docs/installation#post-css-7-compatibility-build

        【讨论】:

        【解决方案8】:

        我在使用 Laravel-mix 5、PostCSS 8 和 Tailwind 2 时遇到了这个问题。
        使用 Laravel-mix 6(目前为测试版)解决了这个问题。

        npm install laravel-mix@next --save-dev
        

        【讨论】:

          【解决方案9】:

          这些步骤对我有用。这是来自github

          npm uninstall tailwindcss postcss autoprefixer
          npm install tailwindcss@latest postcss@latest autoprefixer@latest
          
          npx tailwindcss init -p
          
          npm uninstall tailwindcss postcss autoprefixer
          npm install tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
          

          【讨论】:

            【解决方案10】:
            "dependencies": {
                "autoprefixer": "^9.8.6",
                "postcss": "^8.0.0",
                "postcss-cli": "^8.1.0",
                "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.2",
            },
            

            Dependecies对象和版本可以直接在package.json文件中修改就可以了

            【讨论】:

            • 在 2021 年 4 月,这是唯一对我有用的组合,在 react-tailwind 设置中没有错误,可能是由于 tailwind-compat-build。
            【解决方案11】:

            使用PostCSS 7 compatibility build的官方解决方案修复

            yarn remove tailwindcss postcss autoprefixer
            yarn add -D tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
            

            【讨论】:

              【解决方案12】:

              将 postcss 安装为依赖项。

              npm i postcss
              

              【讨论】:

              • 这与this other answer 中的解决方案相同。 在回答已有答案的旧问题时,请确保提供新颖的解决方案或比现有答案更好的解释。
              【解决方案13】:

              很简单,

              npm install postcss@^8 
              

              对我来说效果很好。

              【讨论】:

                猜你喜欢
                • 2021-05-20
                • 2021-03-03
                • 2023-03-16
                • 2021-06-09
                • 2022-01-14
                • 2017-02-26
                • 2018-09-21
                • 2021-12-14
                • 2017-09-07
                相关资源
                最近更新 更多