1

アプリで PrimeReact DataTable を使用したいと考えています。css ファイルをインポートすると、次のようになります。

import "primereact/resources/themes/nova-light/theme.css";
import "primereact/resources/primereact.min.css";
import "primeicons/primeicons.css";

次のエラーがスローされます。

ERROR in ./node_modules/primereact/resources/themes/nova-light/theme.css 1:0
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @charset "UTF-8";
| /* open-sans-300 - latin */
| @font-face {
 @ ./src/pages/_app.js 20:0-58
 @ ./src/index.js

ERROR in ./node_modules/primeicons/primeicons.css 1:0
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @font-face {
|     font-family: 'PrimeIcons';
|     font-display: auto;
 @ ./src/pages/_app.js 22:0-35
 @ ./src/index.js

ERROR in ./node_modules/primereact/resources/primereact.min.css 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

次のように webpack.config.js を調整しました。

var path = require("path");

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        exclude: [
          path.resolve("node_modules/primereact/resources/primereact.css"),
          path.resolve(
            "node_modules/primereact/resources/themes/nova-light/theme.css"
          )
        ],
        use: [
          // Creates `style` nodes from JS strings
          "style-loader",
          // Translates CSS into CommonJS
          "css-loader",
          // Compiles Sass to CSS
          "sass-loader"
        ]
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  },
  externals: {
    Config: JSON.stringify(
      process.env.NODE_ENV === "production"
        ? require("./config.prod.json")
        : require("./config.dev.json")
    )
  }
};

同様の質問に対する他の回答は時代遅れに見えます。それらを行うと、他のエラーまたは同じものがスローされるからです。

4

2 に答える 2