I had this same problem and solved it by renaming my css file to:

myName.module.css

and also importing like this:

import styles from './myName.module.css'

There is no need to follow the steps of updating the webpack files any more.

Answer from pflevy on Stack Overflow
🌐
GitHub
github.com › vercel › next.js › issues › 36873
module.css not loading styles · Issue #36873 · vercel/next.js
March 17, 2022 - /*/components/Livestream/App.module.css*/ .container main { align-items: center; display: flex; height: 100vh; justify-content: center; } .container main .live-stream { background-color: #000615; display: flex; height: 100%; overflow: hidden; position: relative; width: 100%; } However only the main tag gets the css styling and not the class live-stream:
Published   May 12, 2022
Author   andres-dejesus
Discussions

sass CSS Module Not Working
Bug report Describe the bug I am trying to use a sass CSS module, however I do not see the styles taking effect on the page. I followed instructions both here: https://nextjs.org/blog/next-9-3#buil... More on github.com
🌐 github.com
7
March 18, 2020
reactjs - Module.css is not working in React.So css can't proceed either. Please reply - Stack Overflow
First of all, I made a project with RCA. And I used the CSS Module. It went well at first, but suddenly there was a problem. As shown in the picture above, classname was assigned to the div tag, but More on stackoverflow.com
🌐 stackoverflow.com
"Cannot resolve module" for CSS files
When I try to require CSS files, I get an error: ERROR in ./src/client/scripts/display-test.js Module not found: Error: Cannot resolve module 'style' in C:\Users\u659408\localhost\bp\src\cl... More on github.com
🌐 github.com
24
August 9, 2015
In v5 can't use import * as styles with css modules, bug?
Hello, after upgrading to v5 I can not use anymore named import such as import * as styles from './Table.module.css'; This results in the following error export 'table' (imported as 'styles') was n... More on github.com
🌐 github.com
11
September 20, 2021
🌐
Reddit
reddit.com › r/reactjs › css module not working, maybe because of newwindowcomponent.js
r/reactjs on Reddit: CSS module not working, maybe because of NewWindowComponent.js
January 21, 2021 -

Right now I made another component that is on a new window called Blog.js. In-line styling is convenient but eventually it will get crowded and annoying to edit. I want to make another stylesheet using CSS module called Blog.module.css but when I style in it and import in Blog.js, it clashes with App.js component instead. Here's my code on stackoverflow: [https://stackoverflow.com/questions/69792331/how-do-i-make-a-new-css-file-for-a-new-component-in-react-js]

🌐
GitHub
github.com › vercel › next.js › issues › 11186
sass CSS Module Not Working · Issue #11186 · vercel/next.js
March 18, 2020 - import style from "./Header.module.scss"; export default function Header() { return ( <div className={style.header}> <p>Logo</p> </div> ); } ... I expect the Header component to have the styles applied. ... In the dev tools, I see the random class name assigned to the component: however the ''header" class is not applied, and even if i add the class manually in the dev tools, i do not see the styles applied.
Author   cbonaco1
🌐
GitHub
github.com › webpack › webpack › issues › 1470
"Cannot resolve module" for CSS files · Issue #1470 · webpack/webpack
August 9, 2015 - When I try to require CSS files, I get an error: ERROR in ./src/client/scripts/display-test.js Module not found: Error: Cannot resolve module 'style' in C:\Users\u659408\localhost\bp\src\client\scripts @ ./src/client/scripts/display-test...
Author   joezimjs
🌐
GitHub
github.com › facebook › create-react-app › issues › 11800
In v5 can't use import * as styles with css modules, bug? · Issue #11800 · facebook/create-react-app
September 20, 2021 - Hello, after upgrading to v5 I can not use anymore named import such as import * as styles from './Table.module.css'; This results in the following error export 'table' (imported as 'styles') was not found in './Table.module.css' (possib...
Author   mikoleg
Find elsewhere
🌐
Stack Exchange
drupal.stackexchange.com › questions › 311570 › css-in-custom-module-not-loading
views - CSS in custom module not loading - Drupal Answers
The method you are using is listed in Adding assets (CSS, JS) to a Drupal theme via *.libraries.yml / Attaching a library to all pages, which also says: If you prefer attaching a library from within your module you can use hook_preprocess_HOOK() or hook_page_attachments(). ... The current version of drupal.org/docs/develop/creating-modules/… explicitly says that you can add the libraries key to the info.yml file. It does not seem to work for me, but that's what's documented.
🌐
webpack
webpack.js.org › loaders › css-loader
css-loader | webpack - JS.ORG
Disclaimer: css-loader is a third-party package maintained by community members, it potentially does not have the same support, security policy or license as webpack, and it is not maintained by webpack. The css-loader interprets @import and url() like import/require() and resolves them. ... In the example configuration below, style-loader is used to inject the processed CSS into the DOM during runtime. You may need to install it as well: ... Then, add the loader to your webpack configuration. For example: ... module.exports = { module: { rules: [ { test: /\.css$/i, use: ["style-loader", "css-loader"], }, ], }, };
🌐
GitHub
github.com › css-modules › css-modules › issues
css-modules/css-modules
April 25, 2022 - css-modules / css-modules Public · Notifications · You must be signed in to change notification settings · Fork 562 · Star 17.8k · Preview · Search Issues · is:issue state:open · is:issue state:openClear filterSearch · LabelsMilestonesNew issue · Open · Closed ·
Author   css-modules
🌐
Reddit
reddit.com › r/learnjavascript › trying to add css modules to my react project in my js file
r/learnjavascript on Reddit: Trying to add CSS Modules to my react project in my js file
June 20, 2024 -

I'm having a problem when using CSS Modules with React + Webpack where my variable styles is undefined and nothing can be found. I'm using the following in my project:

"devDependencies": {
    "@babel/core": "^7.24.7",
    "@babel/preset-env": "^7.24.7",
    "@babel/preset-react": "^7.24.7",
    "babel-loader": "^9.1.3",
    "css-loader": "^7.1.2",
    "file-loader": "^6.2.0",
    "html-webpack-plugin": "^5.6.0",
    "style-loader": "^4.0.0",
    "webpack": "^5.91.0",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^5.0.4"
  }

My webpack.config.js:

const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: './src/index.js',

    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'bundle.js'
    },

    plugins: [
        new HTMLWebpackPlugin({
            template: './src/index.html'
        })
    ],

    module: {
        rules: [
            {
                test: /.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            '@babel/preset-env',
                            '@babel/preset-react'
                        ]
                    }
                }
            },
            {
                test: /\.(png)$/i,
                use: [
                    {
                        loader: 'file-loader',
                    }
                ]
            },
            {
                test: /\.css$/,
                use: ['style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            importLoaders: 1,
                            modules: true
                        }
                    }
                ]
            }
        ]
    }
}

I have a file called TestComponent.js which has:

import React from 'react';
import styles from './Test.module.css';

function TestComponent() {
    console.log(styles);

    return (
        <div className={styles.a}>
            <p>
                Random text Random text Random text Random text Random text Random text
            </p>
        </div>
    );
}

export default TestComponent;

My css file is called Test.module.css:

.a {
    border-style: solid;
    border-color: green;
    border-width: 2px;
}

Not sure what is going wrong? I've tried a few things so far...

Using: "import * as styles" seems to work but every guide I see online shows the way I did it above, so I'm confused as to why it wont work?

I found that using "import { a } from './Test.module.css';" works, but I still cannot get it to work if I try to do it the above way.

If I remain using styles but don't actually use it in a className it does get added into the index.html header as a style tag. I'm just unable to use it in the component.

I've also adjusted webpack.config.js a bit without any luck

{
    test: /\.css$/, // Apply CSS Modules only to .module.css files
    exclude: /\.module\.css$/,
    use: ['style-loader', 'css-loader']
    },
    {
    test: /\.module\.css$/, // Apply CSS Modules only to .module.css files
    use: [
        'style-loader', // Inject styles into the DOM
        {
        loader: 'css-loader', // Translates CSS into CommonJS
        options: {
            modules: {
            localIdentName: '[name]__[local]__[hash:base64:5]', // Custom naming pattern for CSS Modules
            },
        },
        },
    ],
    }

Github repo: https://github.com/randobanohando/testprj

🌐
HubSpot
community.hubspot.com › t5 › CMS-Development › Some-CSS-Stylings-for-Module-not-being-applied › m-p › 707797
Solved: HubSpot Community - Some CSS Stylings for Module not being applied - HubSpot Community
October 20, 2022 - It looks like its the .blog-card-topic a that's being set somewhere else. A blog.css file maybe? IOr from another module on the page? In any case I think the quickest workaround would be targeting more specifically.
🌐
Reddit
reddit.com › r/reactjs › css modules is not working in functional component help?????
r/reactjs on Reddit: CSS Modules is not working in functional component Help?????
March 19, 2020 -

i am facing issue when i am trying to scope css file to specific component in case of class component its working fine by following this article https://create-react-app.dev/docs/adding-a-css-modules-stylesheet

but in functional component this approach is not working

here is some my application details
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-scripts": "3.4.0"

here is my component
import React, { Component } from 'react';
import LS from './Layout.module.css';
// import './Layout.css'
import Aux from '../../hoc/Aux';

// const layout = (props) => (
//
// Toolbar Sidebar BackDrop
//
// {props.children}
//
//
// );

class layout extends Component {
render() {
return (

Toolbar Sidebar BackDrop

{this.children}

);
}
}
export default layout;

when i apply class approach the css is only scope to the layout file but i want to use finctional component but the scope css is not working when i use functional component

🌐
GitHub
github.com › preactjs › wmr › issues › 259
Typescript error for css module imports · Issue #259 · preactjs/wmr
December 16, 2020 - Using the default demo template, I get the following error in any index.js file when importing from css (modules): Cannot find module './style.module.css' or its corresponding type declarations. I recommend using a d.ts file for common n...
Author   ivancuric
Top answer
1 of 6
1

i'm using material-ui and I kind of faced the same problem, I had Header and Footer component inside of layout.js and none of my styles was applying till I used !important which is really annoying. so what I did was injecting my css to material ui on the top of my component trees like this :

 import { StyledEngineProvider } from '@mui/material/styles'

    export default function RootLayout({ children }) {
  return (
    <html lang="fa-IR" dir='rtl' className={vazir.className}>
      <body>
        <StyledEngineProvider injectFirst> //this part is important
          <MainTheme>
            <MainContext>
              <DesktopHeader />
              <MobileHeader />
              <Box sx={{ backgroundColor: '#101820' }}>
                {children}
                <Footer />
              </Box>
            </MainContext>
          </MainTheme>
        </StyledEngineProvider>
      </body>
    </html >
  )
}
2 of 6
1

Just to add my own point as I had a 'not working .module.css issue too'

In my case, my css class names was using hyphen (-)

into my component_foo.module.css:

/* NOT WORKING */
.inclined-bg-type1 {
    background-color: orange;
}

was converted into inclinedBgType1 in my component_foo.tsx but was not applied (after import styles from './component_foo.module.css')

<div className={`h-96 w-full ${styles.inclinedBgType1}`}></div>

CORRECTED BY USING _ instead of -:

.inclined_bg_type1 {
    background-color: orange;
}

leads to inclined_bg_type1

<div className={`h-96 w-full ${styles.inclined_bg_type1}`}></div>

and works just as expected.

It is a known behavior (https://github.com/facebook/create-react-app/issues/11155) but I still spend an hour trying to correct it.

If it may help others...

🌐
Reddit
reddit.com › r/nextjs › vs code can't find module.css files
r/nextjs on Reddit: VS Code can't find module.css files
September 6, 2023 -

I just upgraded to Next 13 and switched to Typescript, so now I'm rewriting my web site. But VS Code cannot seem to find the module.css files. Files like global.css import just fine. Here's an example:

import './global.css';
import styles from './layout.module.css';

global.css can be found by VS Code, but layout.module.css cannot. However, when the code runs, both of these files import just fine. Any clue as to what I'm doing wrong?