0

我使用 create-react-app(typescripts) 构建了一个项目,并添加了 antd@3.26.13 和 customize-cra,因为我关注的网站告诉我。

我想使用module.css,我想使用module.less,比如css,但是遇到了一些错误信息:

./src/layout/basic.module.less (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/less-loader/dist/cjs.js??ref--6-oneOf-8-3!./src/layout/basic.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? }

我的代码如下:

const {
    override,
    addWebpackAlias,
    fixBabelImports,
    addLessLoader,
    addDecoratorsLegacy
} = require('customize-cra');

module.exports = override(
    addWebpackAlias({
        "@":require('path').resolve(__dirname,"src")
    }),
    fixBabelImports('import',{
        libraryName:'antd',
        libraryDirectory:'es',
        style:true
    }),
    addLessLoader({
        javascriptEnabled:true,
        modifyVars:{'@primary-color':'#1DA57A'},
    }),
    addDecoratorsLegacy()
);

4

1 回答 1

2

当前版本customize-cra与 的最新版本不兼容,create-react-app确切地说是与css-loader. 尝试安装customize-cra@next以获取 alpha 版本。他们在那里解决了这个问题。

于 2020-04-03T06:22:30.697 回答