-
Notifications
You must be signed in to change notification settings - Fork 1.5k
postcss-loader 'config' validation error #2784
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
Comments
As a hotfix I added the following to my environment.loaders.keys().forEach(loaderName => {
let loader = environment.loaders.get(loaderName);
loader.use.forEach(loaderConfig => {
if (loaderConfig.options && loaderConfig.options.config) {
loaderConfig.options.postcssOptions = loaderConfig.options.config;
delete loaderConfig.options.config;
}
});
}); |
How great! Works like a charm, thx a lot! :) |
Thanks @ChadMoran! I tweaked your solution to be a little more explicit, and to specifically check if the loader in question is function hotfixPostcssLoaderConfig (subloader) {
const subloaderName = subloader.loader
if (subloaderName === 'postcss-loader') {
subloader.options.postcssOptions = subloader.options.config;
delete subloader.options.config;
}
}
environment.loaders.keys().forEach(loaderName => {
const loader = environment.loaders.get(loaderName);
loader.use.forEach(hotfixPostcssLoaderConfig);
}); |
function hotfixPostcssLoaderConfig (subloader) {
const subloaderName = subloader.loader
if (subloaderName === 'postcss-loader') {
if (subloader.options.postcssOptions) {
console.log(
'\x1b[31m%s\x1b[0m',
'Remove postcssOptions workaround in config/webpack/environment.js'
)
} else {
subloader.options.postcssOptions = subloader.options.config;
delete subloader.options.config;
}
}
}
environment.loaders.keys().forEach(loaderName => {
const loader = environment.loaders.get(loaderName);
loader.use.forEach(hotfixPostcssLoaderConfig);
}); Working off @noise-machines (and therefore @ChadMoran), I added a log line that yells at me when this is no longer necessary. It prints the text in red. Also, I'm pretty sure when this isn't necessary anymore, |
I'm seeing this issue as well. |
I tried both workarounds shared here, but its giving me the following error:
My pachage.json has the following pagackages:
Any idea? |
Never mind. I had to change the version number to 4.2.0 : "postcss-loader": "4.2.0", Version 5.0.0 was just released with a breaking change. |
We were seeing Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema. options has an unknown property 'config'. These properties are valid: object { postcssOptions?, execute?, sourceMap? } This patch seems to fix it rails/webpacker#2784 at least until we can upgrade properly.
We were seeing Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema. options has an unknown property 'config'. These properties are valid: object { postcssOptions?, execute?, sourceMap? } This patch seems to fix it rails/webpacker#2784 at least until we can upgrade properly.
God bless you for this the hotfix, @ChadMoran. 2 years later and this is (still) the way... |
@mcmaddox Webpacker is retired. You should consider switching to jsbundling-rails and maintaining your own Webpack config, or webpacker's actively maintained fork shakapacker. There's more information in Webpacker's readme. |
@natematykiewicz In your opinion, which solution is preferred for an app that hasn't migrated to Rails 7 yet (still on 6.1)? |
It all depends on how much you like Webpack vs the other bundlers (rollup, esbuild), and if you prefer webpack do you want to maintain your own config. jsbundling-rails is unopiniated. It's simply a gem that runs your bundler of choice and wires its output into the asset pipeline for serving. Shakapacker continues off where webpacker left off. Some people really like webpack and want an automatic config (Shakapacker). Others like webpack but want to configure it themselves, or prefer something faster like esbuild, so they use jsbundling-rails. This discussion gives you a ton of information about the topic. https://discuss.rubyonrails.org/t/guide-to-rails-7-and-the-asset-pipeline/80851 I personally have switched employers and only use Hotwire these days. |
@natematykiewicz Thanks for the link! |
Uh oh!
There was an error while loading. Please reload this page.
I've updated to postcss 8.1.0 and postcss-loader 4.0.3 and get this validation error now:
After some research I've found out that postcss-loader has changed their options hash. They lie now under "postcssOption".
Therefore this:
should be changed to:
(in package/utils/get_style_rule.js.)
Is it legit to do this manually to resolve this issue temporary? (in my node_modules folder)
The text was updated successfully, but these errors were encountered: