css-loader@2.11显示错误消息:找不到模块:错误:无法解析“ css-loader / locals”

时间:2019-05-06 08:04:17

标签: webpack css-loader

在集成css-loader@2.11时,出现以下错误:

css-loader/locals not found

但是,当我降级到css-loader@0.28.10时,一切正常。我本人试图在css-loader中跟踪代码,但仍然找不到问题。

尽管我怀疑这是css-loader的问题,因为它似乎可以毫无问题地执行(它通过我放入代码中的调试日志执行)。

以下是我的.css规则的Webpack设置:

base.webpack.config.js

        {
          test: /\.css$/,
          use: [
            {
              loader: 'style-loader'
            },
            {
              loader: 'css-loader',
              options: {
                modules: true, // enable css module
                importLoaders: 2 ,
                localIdentName: '[name]__[local]__[hash:base64:5]',
                exportOnlyLocals: true,
              },
            },
            'postcss-loader',
            'sass-loader',
          ],
        },

package.json

  "devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/plugin-proposal-class-properties": "^7.4.4",
    "@babel/plugin-transform-runtime": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "babel-loader": "^8.0.5",
    "clean-webpack-plugin": "^2.0.1",
    "concurrently": "^4.1.0",
    "css-loader": "^2.1.1",
    "file-loader": "^3.0.1",
    "image-webpack-loader": "^4.6.0",
    "mini-css-extract-plugin": "^0.6.0",
    "node-sass": "^4.12.0",
    "postcss-flexibility": "^2.0.0",
    "postcss-loader": "^3.0.0",
    "postcss-smart-import": "^0.7.6",
    "precss": "^4.0.0",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.1",
    "universal-webpack": "^0.6.11",
    "url-loader": "^1.1.2",
    "webpack": "^4.30.0",
    "webpack-cli": "^3.3.0",
    "webpack-dev-middleware": "^3.6.2",
    "webpack-hot-middleware": "^2.24.3"
  },
  "dependencies": {
    "@babel/cli": "^7.4.3",
    "@babel/polyfill": "^7.4.3",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.4.0",
    "@babel/runtime": "^7.4.3",
    "dotenv": "^7.0.0",
    "express": "^4.16.4",
    "normalize.css": "^8.0.1",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "styled-components": "^4.2.0"

请给我指导以解决此问题。谢谢!

0 个答案:

没有答案