storybookjs / addon-styling

A base addon for configuring popular styling tools
MIT License
44 stars 10 forks source link

[Bug] Postcss + CSS modules syntax error on import (unknown word) #43

Closed equinusocio closed 1 year ago

equinusocio commented 1 year ago

Describe the bug

Error on rendering components with basic CSS (using Postcss and CSS Modules). See screenshot.

Here the CSS file:

  .Autocomplete {
    display: unset;
  }

  .OptionsList {
    max-block-size: var(--max-h);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

Addon configuration:

    {
      name: '@storybook/addon-styling',
      options: {
        cssModules: true,
        postCss: {
          implementation: require('postcss'),
        },
      },
    },

Steps to reproduce the behavior

  1. Create a css module and import it inside a react typescript (tsx) component.

Expected behavior

No errors.

Screenshots and/or logs

CleanShot 2023-05-19 at 14 40 41

Environment

Additional context

With the old plugin addon-postcss everything worked as expected.

ShaunEvening commented 1 year ago

@equinusocio, this is a case of loaders being applied multiple times. can you share your main.(js|ts) with me?

equinusocio commented 1 year ago
import type { StorybookConfig } from '@storybook/react-webpack5';
import path from 'node:path'

const config: StorybookConfig = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  docs: {
    autodocs: true,
  },
  features: {
    storyStoreV7: true,
  },
  addons: [
    '@storybook/addon-actions',
    '@storybook/addon-links',
    'storybook-css-modules-preset',
    'storybook-addon-themes',
    {
      name: '@storybook/addon-essentials',
      options: {
        backgrounds: false,
      },
    }, {
      name: '@storybook/addon-styling',
      options: {
        cssModules: true,
        postCss: {
          implementation: require('postcss'),
        },
      },
    },
  ],
  typescript: {
    check: false,
    checkOptions: {},
    reactDocgen: 'react-docgen-typescript',
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      propFilter: prop => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
    },
  },
  webpackFinal: async (config) => {
    if (config && config.resolve && config.resolve.alias) {
      config.resolve.alias['@/components'] = path.resolve(__dirname, '../src/');
      return config;
    }
    return config;
  },
  framework: {
    name: '@storybook/react-webpack5',
    options: {},
  },
};

export default config;
equinusocio commented 1 year ago

Got it. I didn't try to remove addons one by one. The issue is caused by storybook-css-modules-preset. By removing it everything seems to work as expected. Thanks for the patience

ShaunEvening commented 1 year ago

That's great news @equinusocio! I'm glad you got it figured out 🎉