Allow importing CSS modules from other NPM packages
See original GitHub issueFeature 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:
- Handle my private packages as “global-CSS”
- Pre-compile all my components to not have a CSS import statement.
Current error:
error - ./node_modules/react-modern-calendar/dist/esm/components/Calendar/index.module.css
CSS Modules cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-modules-npm
Additional context
Next.js: 9.4.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:194
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Allow importing CSS modules from other NPM packages
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 ......
Read more >how to export and import style in npm package? - Stack Overflow
1 Answer 1 · 3. For webpack, do npm install --save-dev css-loader . Then in your webpack.config.js, add this line to the use...
Read more >Using CSS Module Scripts to import stylesheets - web.dev
Learn how to use CSS module scripts to import CSS stylesheets using the same syntax as JavaScript modules.
Read more >postcss-import - npm
PostCSS plugin to transform @import rules by inlining content. This plugin can consume local files, node modules or web_modules. To resolve path ...
Read more >css-loader - npm
Allows to enables/disables or setups number of loaders applied before CSS loader for @import at-rules, CSS modules and ICSS imports, i.e. @ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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
.module.css
naming issue for now.This sort of reminds me of the
.js
versus.mjs
debate… how a file extension for essentially the same format changes the way in which others interpret it..mjs
was at least championed by the Node.js team, but as for interpreting a CSS file as either a local module or global, I can’t imagine any organization declaring a standard. It’s more a responsibility of the bundlers, and if any bundler was going to create a defacto standard for this, it would be Webpack……well it turns out Webpack already seems to have settled upon the
.module.css
extension. Take a look at the docs for the css-loader: https://webpack.js.org/loaders/css-loader/#auto . If you configuremodules:true
themodules{auto:true}
is implied, which results in any filenames matching/\.module\.\w+$/i
being interpreted as a local CSS modules.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!