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

Enable CSS Module report an error #37

Closed
ghost opened this issue Mar 26, 2020 · 1 comment
Closed

Enable CSS Module report an error #37

ghost opened this issue Mar 26, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 26, 2020

Hi, I tried to enable CSS module support for less, but when the project started, I encountered an error and couldn't continue:

./src/App.module.less (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-8-3!./node_modules/less-loader/dist/cjs.js??ref--6-oneOf-8-4!./src/App.module.less)
ValidationError: Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'localIdentName'. These properties are valid:
   object { url?, import?, modules?, sourceMap?, importLoaders?, localsConvention?, onlyLocals?, esModule? }

Here is my config:

// Don't open the browser during development
process.env.BROWSER = "none";

module.exports = {
  plugins: [
    {
      plugin: require('craco-less'),
      options: {
        modifyLessRule: function (lessRule, _context) {
          lessRule.test = /\.(module)\.(less)$/;
          lessRule.exclude = /node_modules/;
          return lessRule;
        },
        cssLoaderOptions: {
          modules: true,
          localIdentName: "[local]_[hash:base64:8]"
        }
      }
    }
  ]
};

How can I solve this problem? Thank you!

@ghost
Copy link
Author

ghost commented Mar 30, 2020

Hi, I fixed this error:

// Don't open the browser during development
process.env.BROWSER = "none";

module.exports = {
  plugins: [
    {
      plugin: require('craco-less'), // Enable less support.
    },
    {
      plugin: require('craco-less'), // Enable less support with CSS module.
      options: {
        modifyLessRule: function (lessRule, _context) {
          lessRule.test = /\.(module)\.(less)$/;
          lessRule.exclude = /node_modules/;
          return lessRule;
        },
        cssLoaderOptions: {
          modules: {
            localIdentName: "[hash]",
          }
        }
      }
    }
  ]
};

@ghost ghost closed this as completed Mar 30, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants