Replies: 14 comments
-
Have you tried next-transpile-modules? |
Beta Was this translation helpful? Give feedback.
-
Hi @arnaudpeich thanks for the workaround. With this issue I'd like to request first-class support in Next.js. |
Beta Was this translation helpful? Give feedback.
-
The three biggest problems I see are:
So, allowing CSS modules within
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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! 😉 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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! |
Beta Was this translation helpful? Give feedback.
-
The postcss plugin for rollup does the same: https://www.npmjs.com/package/rollup-plugin-postcss#automodules |
Beta Was this translation helpful? Give feedback.
-
Hi :) Let me know if this is unrelated to this issue and should open a new one. |
Beta Was this translation helpful? Give feedback.
-
I really appreciate that many things are now bundled 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:
|
Beta Was this translation helpful? Give feedback.
-
Here's a related RFC: #27953 In particular:
|
Beta Was this translation helpful? Give feedback.
-
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
Beta Was this translation helpful? Give feedback.
All reactions