【问题标题】:Module not found: Error: Can't find options with ident 'postcss'找不到模块:错误:找不到带有 ident 'postcss' 的选项
【发布时间】:2019-02-16 07:40:58
【问题描述】:

我是 stackoverflow 的新手,想问你一个我在互联网上从未找到过的问题......我希望我在好网站上 :)

所以这是我的问题:我想将一些 css 文件从 node_modules 依赖项导入到反应应用程序。我使用 webpack 进行开发,但出现了一个我不明白的错误,这在标题中。 所以这是编译器的错误详细信息:

    ERROR in ./src/scss/app.scss
Module not found: Error: Can't find options with ident 'postcss'
 @ ./src/scss/app.scss 9:10-188
 @ ./src/app/App.js
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 (webpack)/hot/dev-server.js ./src

另外,在导航控制台中我得到了这个:

Error: Cannot find module '-!../../node_modules/css-loader/index.js?{"importLoaders":1}!../../node_modules/postcss-loader/lib/index.js??postcss!react-big-calendar/lib/css/react-big-calendar.css'

那是我的 scss 文件的内容无法加载 css 文件。 应用程序.scss:

exports.i(require("-!../../node_modules/css-loader/index.js?{\"importLoaders\":1}!../../node_modules/postcss-loader/lib/index.js??postcss!react-big-calendar/lib/css/react-big-calendar.css"), "");

你也可以查看我的 webpack 配置文件:

const HtmlWebPackPlugin = require("html-webpack-plugin");

const htmlWebpackPlugin = new HtmlWebPackPlugin({
  template: "./src/index.html",
  filename: "./index.html"
});

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          { loader: 'css-loader', options: { importLoaders: 1 } },
          'postcss-loader'
        ]
      }
    ]
  },
  plugins: [htmlWebpackPlugin],
  resolve: {
    extensions: ['.js', '.jsx', '.json', '.css']
  }
};

我的代码有什么问题?

非常感谢你帮助我!如果我不是很清楚,请询问我任何其他信息

【问题讨论】:

  • 看来你缺少 postcss-loader
  • 您好,很抱歉回复时间太长了。 postcss-loader 有什么问题?
  • 要么没有安装,要么没有 postcss 配置文件。

标签: reactjs postcss webpack-4 css-loader postcss-loader


【解决方案1】:

您可能需要将您的 postcss-loader 配置更改为此。取决于您拥有的加载程序版本,从 4.0.0 开始不需要 (https://github.com/webpack-contrib/postcss-loader/releases/tag/v4.0.0)

{
  loader: 'postcss-loader',
  options: {
    ident: 'postcss',
  },
}

【讨论】:

    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 2018-09-10
    • 2020-01-25
    • 2014-04-21
    • 2018-12-30
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    相关资源
    最近更新 更多