【问题标题】:Module parse failed: Unexpected character '@' (1:0)模块解析失败:意外字符“@”(1:0)
【发布时间】:2020-06-09 12:57:58
【问题描述】:

我是 Webpack 和 React 的真正初学者。 我想使用一些 npm (carousel multi react),但我不能。我的 webpack.config 有问题。 不幸的是,我自己无法解决这个问题,我看到了一些类似的主题,但它对我不起作用......或者我只是不知道如何在我的文件中实施解决方案。

./node_modules/react-multi-carousel/lib/styles.css 1:0 中的错误 模块解析失败:意外字符“@”(1:0) 您可能需要适当的加载程序来处理此文件类型,目前没有配置加载程序来处理此文件。见https://webpack.js.org/concepts#loaders

const path = require("path");

const Html = require('html-webpack-plugin');

module.exports = {
  entry: [
    "whatwg-fetch",
    "./js/index.js",
  ],
  output: { 
    filename: "js/out.js",
    path: path.resolve(__dirname, "build")
  },
  devServer: {
    port: 3001,
  },
  module: {
    rules: [

      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        }
      },

      {
        test: /\.scss$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: "postcss-loader",
            options: {
              plugins: () => [
                require("autoprefixer")()
              ],
            },
          },
          'sass-loader',
        ]
      },

      {
        test: /\.(jpg|jpeg|gif|png)$/,
        use: {
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            publicPath: 'images',
            outputPath: 'images',
          }
        }
      },

      {
        test: /\.(eot|ttf|woff|woff2)$/,
        use: {
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            publicPath: 'fonts',
            outputPath: 'fonts',
          }
        }
      },
    ]
  },

  plugins: [
    new Html({
        filename: 'index.html',
        template: './index.html',
    })
  ]
};

【问题讨论】:

标签: reactjs react-native webpack


【解决方案1】:

尝试将以下 json 添加到规则数组中。

  {
    test: /\.(sass|less|css)$/,
    loaders: ['style-loader', 'css-loader', 'less-loader']
  }

还要为上述加载器安装所需的 npm 模块, 或者您也可以尝试将test: /\.(sass|css)$/, 添加到您当前的设置中。

【讨论】:

    【解决方案2】:

    谢谢!它正在工作。 ;)

       {
            test: /\.(sass|css|scss)$/,
            use: [
              'style-loader',
              'css-loader',
              {
                loader: "postcss-loader",
                options: {
                  plugins: () => [
                    require("autoprefixer")()
                  ],
                },
              },
              'sass-loader',
            ]
          },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 2021-03-18
      • 2019-08-04
      • 2019-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多