-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
postcss-preset-env
dynamically skips plugins with importFrom
/exportTo
based on browser lists
#140
Comments
In my environment |
@equinusocio we've been discussing Thanks a lot for taking the time to chime in here! |
@equinusocio Preferably in a separate issue if possible as it is likely separate from the case describe here. This issue is more about how postcss-preset-env can skip plugins if allowed by browser lists. That will make it easier to follow up your case :) |
postcss-preset-env
does not correctly support importFrom
/exportTo
in plugins that have this featurepostcss-preset-env
dynamically skips plugins with importFrom
/exportTo
based on browser lists
@Antonio-Laguna I think we might need to resolve this sooner than later. This also just broken our CI (see last couple commits) @equinusocio I was wrong, it's exactly the same issue :) |
More details for
I think we need to split this one up :
The same approach might be needed for all these plugins :/ |
Here the replication on codesandbox https://codesandbox.io/s/eloquent-northcutt-fwee7?file=/postcss.config.js:120-1199 I can confirm that setting a browserslist in "browserslist": [
"last 2 Chrome versions",
"last 2 Firefox versions",
"last 2 Safari versions",
"last 2 Edge versions"
], Also leaving the browserslist with the default values fix it:
I saw the fix, I would like to test it if you can release it as alpha/beta/next channel. |
There is no alpha/beta/next channel. Please be aware that the fix we have to roll out for this goes against the purpose of My personal preference at this time is to extract the We do have to consider the maintenance cost of this as just keeping preset-env healthy and up to date is already a lot of work :) Maybe there are existing alternatives to do this kind of injection? |
Yeah, i agree, just give us the time to migrate. Wanda design system is built on top of this functionality and it's also a big project and we need time to migrate it. A temp fix is enough for now. I would probably go for postcss-jit-props and use standard |
It's a breaking change and we don't have any plans for another major version (with this kind of breaks), so you got time 😄 This fix should keep everything stable even if anything changes in browser lists. jit-props looks like a good fit! |
Since I'm using this feature like @equinusocio, I would like to try to build a plugin for this using the current implementation of |
@LasaleFamine @equinusocio this is getting released in a bit |
@LasaleFamine In theory you can just take out the entire plugin directory and move it to a new repo. relevant bits :
You would have to move a lot of things around to "un-mono-repo" the setup. |
Thank you @romainmenke, I'm going to take a look and maybe trying an initial setup. |
Got released as @equinusocio and @LasaleFamine if you could test on your end that'd be awesome. |
There is some error (this version completely broke the pipeline): Repruduction CSS .Hello {
color: hsl(env(--color-blue-10));
background-color: hsl(env(--color-blue-60));
padding: env(--space-24);
} ./pages/index.module.css
error - ./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[2].oneOf[4].use[1]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[2].oneOf[4].use[2]!./pages/index.module.css
Error: Invalid source object: [object Object]
at Array.map (<anonymous>)
at Array.map (<anonymous>) ModuleBuildError: Module build failed (from ./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js):
Error: Invalid source object: [object Object]
at /sandbox/node_modules/postcss-custom-properties/dist/index.cjs:1:2182
at Array.map (<anonymous>)
at y (/sandbox/node_modules/postcss-custom-properties/dist/index.cjs:1:1623)
at Object.q [as plugin] (/sandbox/node_modules/postcss-custom-properties/dist/index.cjs:1:5642)
at /sandbox/node_modules/postcss-preset-env/dist/index.cjs:1:9852
at Array.map (<anonymous>)
at De (/sandbox/node_modules/postcss-preset-env/dist/index.cjs:1:9691)
at /sandbox/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:65:63
at plugin (/sandbox/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:30:44)
at Processor.normalize (/sandbox/node_modules/next/node_modules/postcss/lib/processor.js:40:13) |
@equinusocio This has been fixed in a release we pushed out just now. In your case you have no options for custom properties, which is completely valid. |
@romainmenke I'm still having the issue with 7.2.2. The error is gone but still not working with this browserslist set:
It only works if I remove the browserslist completely or set it to
I made a better playground to test this without nextjs, with autorefresh if you live change the package json (remove the browserslist, wait some seconds). Anyway I think the issue should be reopened at this point |
Was closed by merging the PR This happens because we only currently detect one shape.
We should update this to also account for arrays. |
@equinusocio I've checked here: https://glitch.com/edit/#!/decisive-stone-raptor?path=package.json%3A17%3A33 New version 7.2.3 seems to have finally fixed the underlying issue. Can you confirm on your Next app? Thanks 🙏 |
@Antonio-Laguna 7.2.3 seems fixed. 🎉 Just for sharing as a possible migration step, since we are using The only thing to do is to configure the regex to emulate the behaviour from postcss-preset-env: "postcss-replace": {
pattern: /env\(.*?--([^\s]+?)\)/gi,
data: environmentVariables,
},
This way it matches all the custom |
So happy this is working now 🎉 Another option is to disable the plugins with side effects in preset-env and use them directly (outside of preset-env). That should work at least up until something breaking happens in PostCSS.
I think this won't happen in the next year. It still happens to much that tests are green and something broke for someone, exactly like this case :) After all that we would like to handle some feature requests. So it's very low on our list. |
Good to know! Another reason is that custom envs haven't a spec yet, so it's confusing to use I think we can close this now! Appreciated the quick fix! |
Happy to help! |
Bug description
preset-env is a way to dynamically toggle plugins on and off based on config.
This conflicts with
importFrom
/exportTo
and maybe other options where it is always required to run a certain plugin.I don't see a way for these kinds of options to ever work correctly with
postcss-preset-env
.Source CSS
Expected CSS
Actual CSS
Does it happen with
npx @csstools/csstools-cli <plugin-name> minimal-example.css
?No response
Extra config
What plugin are you experiencing this issue on?
PostCSS Preset Env, PostCSS Custom Properties
Plugin version
latest
What OS are you experiencing this on?
No response
Node Version
latest
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: