Skip to content
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

scss module is not working[Bug] #188

Open
qkreltms opened this issue Feb 11, 2021 · 6 comments
Open

scss module is not working[Bug] #188

qkreltms opened this issue Feb 11, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@qkreltms
Copy link

qkreltms commented Feb 11, 2021

Describe the bug

I've tried to use scss so followed instruction to use @storybook/preset-scss on documentation and importing scss is working

import React from "react"
// this is working
import "./Button.scss"


const Button = () => (
  <button type="button" className={"simpleButton"}>test2</button>
    )

export default Button

but scss module is not working.

import React from "react"
// This is not working
import styles from "./Button.module.scss"

const Button = () => (
   // styles.simpleButton is undefined
  <button type="button" className={styles.simpleButton}>test2</button>
    )

export default Button

Steps to reproduce the behavior

I implemented an example https://github.com/qkreltms/lerna-test1 (webpack branch)

clone my project and type yarn install to install all packages
and type yarn storybook

Expected behavior

Should scss module is working (in the example button's background must be set pink)

Screenshots and/or logs

11

Environment

  • OS: [win10]
  • Node.js version: [v14.15.3]
  • NPM version: [6.14.11]
  • Yarn version [1.16.0]
  • Browser (if applicable): [chrome]
@qkreltms qkreltms added the bug Something isn't working label Feb 11, 2021
@earthtosid
Copy link

Here's my main.js file configuration that works with scss modules

module.exports = {
  stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    {
      name: "@storybook/preset-scss",
      options: {
        cssLoaderOptions: {
          modules: {
            auto: true,
          },
        },
      },
    },
  ],
};

@qkreltms
Copy link
Author

I've tried auto, but failed.

@shenzhongkang
Copy link

I have the same problem with [email protected] and webpack@5.

@dottodot
Copy link

Same problem on [email protected] and webpack@5

@dottodot
Copy link

Actual have it working on another project the only difference being that is webpack@4

@s-o-l-b
Copy link

s-o-l-b commented Mar 28, 2022

I ran into this issue on a Vue 3 project and this seems to be working for me:

// .storybook/main.js

module.exports = {
  stories: [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)",
  ],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/preset-scss",
  ],
  framework: "@storybook/vue3",
  typescript: {
    check: false,
    checkOptions: {},
  },
  webpackFinal: async (config, {
    configType
  }) => {
    config.module.rules.forEach(rule => {
      if (rule.test.test(".scss")) {
        rule.use.forEach(use => {
          if (use.loader.includes("css-loader")) {
            use.options = {
              modules: true,
            };
          }
        });
      }
    });
    return config;
  },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants