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

Composes not working with SCSS files #85

Closed
shuboc opened this issue May 10, 2017 · 7 comments
Closed

Composes not working with SCSS files #85

shuboc opened this issue May 10, 2017 · 7 comments
Labels

Comments

@shuboc
Copy link

shuboc commented May 10, 2017

I am writing .scss files which composes classes from other files like this:

a.scss

.a {
  composes: container from './b.css';
}

Then I get error messages as follows:

Module build failed: CssSyntaxError: /home/shubo/Desktop/babel-plugin-react-css-modules/demo/src/components/AnonymouseStyleResolution.js: postcss-modules-scope: /home/shubo/Desktop/babel-plugin-react-css-modules/demo/src/components/table.scss:4:3: referenced class name "i__imported_container_0" in composes not found

I am using filetypes options to parse .scss files in my webpack config (to keep things simple, I use only css-loader for scss files):

    loaders: [
      {
        include: path.resolve(__dirname, './src'),
        loaders: [
          'style-loader',
          'css-loader?importLoader=1&modules&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
        ],
        test: /\.(css|scss)$/
      },
      {
        include: path.resolve(__dirname, './src'),
        loader: 'babel-loader',
        query: {
          plugins: [
            'transform-react-jsx',
            [
              'react-css-modules',
              {
                context,
                filetypes: {
                  '.scss': 'postcss-scss'
                }
              }
            ]
          ]
        },
        test: /\.js$/
      }
    ]

If I modify the config above as filetypes: {'.scss': ''}, the error goes away.

My guess is the file (b.css) containing the class being composed with is somehow not properly parsed or loaded.

Is there any missing postcss configuration I should add or ideas on how to fix it? Thanks in advance.

@gajus gajus added the question label May 10, 2017
@dsempel
Copy link

dsempel commented Jun 7, 2017

composes is working for me with SCSS files. Your configuration seems good. Maybe try to import b.css somewhere so it is loaded? Or rename to b.scss.

@mmw
Copy link

mmw commented Jul 5, 2017

I think you need to set generateScopedName in the plugin options. Something like

...
generateScopedName: "[path]___[name]__[local]___[hash:base64:5]",
fileTypes: {...}

@lagunovsky
Copy link

may be

  {
    context,
    filetypes: {
      ".scss": {
        "syntax": "postcss-scss",
        "plugins": ["postcss-icss-composes"]
      }
    }
  }

@ladas-larry
Copy link

@shuboc have you managed to resolve this?

@shuboc
Copy link
Author

shuboc commented Mar 20, 2018

@Dharmoslap The problem seems to be related to the resolution of paths when using syntax like composes: XXX from 'path/to/css';, but I'm not quite sure. Maybe I can keep looking into it and open a PR once I found a solution.

@gajus
Copy link
Owner

gajus commented Mar 21, 2018

Every time this issue comes up it is a result of misconfigured context property. You must use absolute paths to configure context.

@gajus
Copy link
Owner

gajus commented Nov 27, 2018

@gajus gajus closed this as completed Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants