-
Notifications
You must be signed in to change notification settings - Fork 27.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Allow importing CSS modules from other NPM packages #13282
Comments
Have you tried next-transpile-modules? |
Hi @arnaudpeich thanks for the workaround. With this issue I'd like to request first-class support in Next.js. |
The three biggest problems I see are:
So, allowing CSS modules within
|
I don't see it as a problem. That convention is one way to communicate that the styles are coupled to the local component. It's good to have one way.
This could be a use case for a further issue. For now, it's great to include your own UI components in the build pipeline.
This is not related to this issue. You can still use global CSS in
The reference is not correct. We are talking about CSS-Modules not Javascript. In pure CSS-Modules and "pure" is the magic keyword here. Pure CSS-Modules can't produce side-effects like |
Playing devils advocate here (I have a custom Webpack config to import from
Javascript has many frameworks (
I understand that building your own UI components is an option, but I thought we're primarily focusing on
The issue is related in that it's not very easy/practical to rewrite an entire UI library for CSS modules due to a Next limitation. Therefore asking a library that utilizes global CSS to switch to local CSS to avoid this limitation may not be possible nor practical (CSS modules are locally scoped by design and it makes CSS sharing/nested CSS selectors implausible).
Oops! My apologies for assuming CSS That said, I'm on board for allowing global |
This is not the ECMAScript repository 😄 I'm looking for a pragmatic solution. CSS Modules have been adopted across the ecosystem. Parcel, Gatsby, Next.js, Webpack, React just to name a few.
Not necessarily, it depends on the
I think you mean to allow CSS-Modules from |
I incorrectly thought
Again, the My point is that since most UI libraries don't use CSS modules (because of the reasons mentioned above), this feature has very limited usage (as of now). I think a better feature request would be for Next to handle CSS imports like the rest, which I'm aware of is an easier said than done task (or implausible); but significantly better than expecting all libraries to adhere to NextJS's own limitations. In short, don't add a work-around, fix the import order problem! 😉 |
Again, the .module.css convention has been already established in Next.js and this feature is about to extend it. CSS Modules were introduced because they can provide a kind of isolation. We can archive the same isolation in other NPM packages because they use CSS-Modules. The order problem can't be fixed because the order can't be guaranteed. That is the whole point why CSS Modules were introduced. Please open a different issue if you strive for something bigger. |
The CSS module naming convention may be established by Next's Webpack configuration, but it's likely not in use by the majority of 3rd party libraries. CSS modules are a work-around to a problem, but a very opinionated and ridged one at best. If a library doesn't adapt to this ridged convention, then it still won't work in a Next project. Therefore, the usage of this feature is very limited in focus, functionality, and compatibility. |
I would very much like Next to support css modules for third-party libs, but I'll hold off on expressing why. I just want to comment on the This sort of reminds me of the ...well it turns out Webpack already seems to have settled upon the I would kindly ask the Next team to consider going along with this standard! It would make my life as a third-party UI-based CSS-enabled package maintainer much easier! |
The postcss plugin for rollup does the same: https://www.npmjs.com/package/rollup-plugin-postcss#automodules |
Hi :) Let me know if this is unrelated to this issue and should open a new one. |
I really appreciate that many things are new bundle in Next.js by default, but there are some cases which really blocks development. Referring to this documentation, it should work if we import css from our component, instead of dependency importing it inside node_modules Example:
|
Here's a related RFC: #27953 In particular:
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Feature request
Allow importing CSS modules from other NPM packages.
Is your feature request related to a problem? Please describe.
An NPM package is the primitive of code sharing. Therefore monorepo is very common to split the domain into separate NPM packages. It feels very wrong when we can't import React components.
It should be possible to import CSS files from packages that follow the CSS modules convention
*.module.(css|scss)
because Next.js ensures already that CSS Modules are side-effect free.The current solution forces me:
Current error:
Additional context
Next.js: 9.4.2
The text was updated successfully, but these errors were encountered: