babel-plugin-css-modules-transform icon indicating copy to clipboard operation
babel-plugin-css-modules-transform copied to clipboard

Empty styles

Open kevinehosford opened this issue 7 years ago • 4 comments

This plugin seems like the tool I need, but the output always seems to be empty.

var styles = {} // this is always empty

Could this be an issue with the .babelrc?

{
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ],
  "plugins": [
    [
      "css-modules-transform", {
        "camelCase": true,
        "extractCss": "./build/styles/app.css",
        "generateScopedName": "[name]__[local]___[hash:base64:5]",
        "prepend": [
          "postcss-cssnext",
          "postcss-extend",
          "postcss-import"
        ]
      }
    ]
  ]
}

kevinehosford avatar Jul 25 '18 20:07 kevinehosford

Not sure if this is the same problem as you have, but I had this problem when I turned on --inspect in Node.js and had a debugger window open. The Node application wouldn't end properly reporting Waiting for the debugger to disconnect....

The extractCss output wasn't generated as it was waiting for the debugger to close, and force closing the app didn't generate the CSS.

andismith avatar Sep 18 '18 15:09 andismith

Hm. I wasn't using --inspect, just not seeing any generated output.

kevinehosford avatar Sep 24 '18 15:09 kevinehosford

With the setup we have, I noticed that // styled comments in SCSS files will somehow break the plugin and cause an empty styles object.

jjuutila avatar Jun 25 '19 11:06 jjuutila

Wow, thanks for the tip @jjuutila!

It seems like this mostly works because the CSS parser is able to handle most SCSS syntax. But those inline comments break it (specifically, for us it was a single quote in a // comment, causing a CssSyntaxError). To correctly support SCSS, it looks like you need to configure a preprocessor:

// ./path/to/module-exporting-a-function.js
var sass = require('node-sass');
var path = require('path');

module.exports = function processSass(data, filename) {
    var result;
    result = sass.renderSync({
        data: data,
        file: filename
    }).css;
    return result.toString('utf8');
};

What a footgun! #104 seems relevant.

matthewwithanm avatar Aug 21 '20 22:08 matthewwithanm