我正在将我的站点从create-react-app移植到gatsby。我已经添加了gatsby作为依赖项,但现在当我运行gatsby develop时,我得到了以下错误:
Unknown error from PostCSS plugin. Your current PostCSS version is 6.0.23, but autoprefixer uses 7.0.23. Perhaps this is the source of the error below.
我对webpack不是很熟悉,但我的理解是,这是它的配置造成的吗?到目前为止,我已经尝试通过使用yarn工作区从本质上强制css-loader包依赖与autofixer相同的PostCSS版本来解决这个问题。
我猜测最好的解决方案是重新配置webpack,但我不知道该怎么做。搜索也不会产生任何有用的结果。我真的很感谢在这方面的帮助以及对问题所在的解释。
发布于 2019-12-17 05:05:22
gatsby中的PostCSS版本是6.0,但create-react-app中的版本是7.0...您应该首先指定您的PostCSS配置,安装gatsby-plugin-postcss,然后在gatsby-config.js中写入
module.exports = {
siteMetadata: {
title: `Gatsby`,
},
plugins: [
{
resolve: `gatsby-plugin-postcss`,
options: {
cssLoaderOptions: {
camelCase: false,
},
},
},
]
}通过此代码,您可以将PostCSS的版本指定为7.0。但是您需要使其在页面中可见,因此您应该创建一个postcss.config.js和以下代码行
const postcssPresetEnv = require(`postcss-preset-env`)
module.exports = () => ({
plugins: [
postcssPresetEnv({
stage: 0,
}),
],
})https://stackoverflow.com/questions/59013313
复制相似问题