-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gatsby-plugin-postcss): Add required additional level of nesting for postcss-loader options. #27418
fix(gatsby-plugin-postcss): Add required additional level of nesting for postcss-loader options. #27418
Conversation
I retract this. I went digging a bit further and found out that postcss-loader made some very large, backwards-incompatible changes to its API last month with its 4.0.0 release, which involved moving its Given that it looks like Gatsby already made the leap 12 days ago to bump from postcss-loader 3.0.0 to 4.0.2, it looks like I just got unlucky and am probably the first person to attempt to use Gatsby with PostCSS 4.0 with additional plugins. |
"sourceMap": false, | ||
}, | ||
"sourceMap": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, this doesn't actually look right. In the 4.0.0 release of postcss-loader, sourceMap
was left alone at the top level and not put inside of the new postcssOptions
object. Let me see why an extra sourceMap
property is getting placed inside of postcssOptions
in the tests.
…ostcss-loader options.
a139768
to
dd66dad
Compare
@@ -15,22 +15,25 @@ const findCssRules = config => | |||
|
|||
exports.onCreateWebpackConfig = ( | |||
{ actions, stage, loaders, getConfig }, | |||
{ cssLoaderOptions = {}, postCssPlugins, ...postcssOptions } | |||
{ cssLoaderOptions = {}, postCssPlugins, ...postcssLoaderOptions } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed this argument in order to not confuse it with the new postcssOptions
that postcss-loader actually has now. Because the sourceMap
option is still a sibling to postcssOptions
in postcss-loader, we actually have to put the plugins
property in another level of nesting within the actual object named postcssOptions
and not what we had here previously.
As you can see below, the full hierarchy is now:
postcssLoaderOptions === {
postcssOptions: {
plugins: [],
},
sourceMap: true,
}
dd66dad
to
fee4811
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thank you very much for sending this in!
Thanks for the quick review! |
Published in |
Actually, it looks like this didn't fully fix it. Apologies for not fully testing this again after I made significant changes to my fix. Originally, this PR was just a one-line change to unflatten the spread operator on the original line 33 (the one that constructs the options to postcss-loader), and I was able to test it by just hot-editing the installed version of this package in I'm still hitting the exact same error message when I follow the steps in #27417. However, from putting some extra postcssLoaderOptions === {
postcssOptions: {
plugins: [/* function object representing postcss-preset-env */],
},
plugins: [],
} I'm not sure where that I can at least prepare a followup PR that restores the original level of nesting of that |
Description
This is a proposed fix for #27417, which I just reported with a more detailed description of the problem itself.
The issue appears to be this line of
gatsby-plugin-postcss
:gatsby/packages/gatsby-plugin-postcss/src/gatsby-node.js
Line 33 in 3a3c3e7
The
postcssOptions
object is being used with the spread (...
) syntax, meaning that its properties are being included directly to the object literal passed to theoptions
property of the PostCSS loader. This means that theoptions
property evaluates to{ sourceMap: !isProduction, plugins: [/* plugin objects */] }
.This is invalid because the postcss-loader only accepts three top-level options:
execute
,postcssOptions
, andsourceMap
. Theplugins
property belongs to thepostcssOptions
object, but because of the spread operator, it's getting hoisted up a level.Given that the variable name in this Gatsby plugin is spelled exactly as
postcssOptions
, matching the postcss loader option name, I am assuming that this was a mistake and that the original intent was to pass in the entirety of thepostcssOptions
object into the postcss loader.I tested this by hot-editing the version of this file in my
node_modules/
directory with the exact same change to confirm that this fixes it.Documentation
This fixes the plugin to actually match the behavior described by the documentation in https://github.com/gatsbyjs/gatsby/blob/3a3c3e7f0942578b5ee113056d4883c7c277bdd3/docs/docs/post-css.md and https://github.com/gatsbyjs/gatsby/blob/3a3c3e7f0942578b5ee113056d4883c7c277bdd3/packages/gatsby-plugin-postcss/README.md.
Related Issues
Fixes #27417.