【问题标题】:Error: You may need an appropriate loader to handle this file type错误:您可能需要适当的加载程序来处理此文件类型
【发布时间】:2019-07-08 02:08:01
【问题描述】:

尝试设置一个反应网络应用程序,但在尝试通过导入“semantic-ui-css/semantic.min.css”来实现语义 UI 后一直遇到此错误;在 index.jsx 中。

我 npm 安装了 css-loader 和 style-loader,因为这是我在这个新错误之前遇到的错误。

我的猜测是需要调整 webpack.config 以以不同的方式处理加载程序,但我不确定如何进行此操作。

ERROR in ./node_modules/semantic-ui-css/themes/default/assets/fonts/outline-icons.woff
Module parse failed: C:\Users\Shawn\Documents\GitHub\Galavue\Galavue\node_modules\semantic-ui-css\themes\default\assets\fonts\outline-icons.woff Unexpected character ' ' (1:4)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
 @ ./node_modules/css-loader/dist/cjs.js!./node_modules/semantic-ui-css/semantic.min.css 15:42-101
 @ ./node_modules/semantic-ui-css/semantic.min.css
 @ ./react-client/src/index.jsx

包.json

{
  "name": "galavue",
  "version": "0.0.0",
  "description": "Galavue",
  "main": "server.js",
  "author": "Shawn",
  "scripts": {
    "dev": "webpack -d --watch",
    "start": "node ./server/index.js",
    "build": "webpack -p",
    "react-dev": "webpack -d --watch",
    "server-dev": "nodemon server/index.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/www.github.com/shawnSFU.git"
  },
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/www.github.com/shawnSFU/issues"
  },
  "homepage": "https://github.com/www.github.com/shawnSFU#readme",
  "dependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "body-parser": "^1.17.2",
    "express": "^4.15.3",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-router": "^4.1.2",
    "react-router-dom": "^4.1.2",
    "semantic-ui-css": "^2.4.1",
    "semantic-ui-react": "^0.85.0",
    "webpack": "^3.4.1"
  },
  "devDependencies": {
    "css-loader": "^2.1.0",
    "style-loader": "^0.23.1"
  }
}

webpack.config.js

//defines the entry and output points for our application
const path = require('path');
const SRC_DIR = path.join(__dirname, '/react-client/src');
const DIST_DIR = path.join(__dirname, '/react-client/dist');
const webpack = require('webpack');
module.exports = {
    entry: `${SRC_DIR}/index.jsx`,
    output: {
        path: DIST_DIR,
        filename: 'bundle.js',
    },
    resolve: {
        extensions: ['.js', '.jsx', '.json', '.css'],
    },
   
    module: {
        rules: [
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            },
            {
                test: /\.png$/,
                loader: 'url-loader?limit=100000&minetype=image/png'
            },
            {
                test: /\.jpg/,
                loader: 'file-loader'
            },
            {
                test: /\.jsx?/,
                include: SRC_DIR,
                loader: 'babel-loader',
                query: {
                    presets: ['react', 'es2015']
                }
            }
        ]
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('production')
        })
    ]
};

【问题讨论】:

    标签: reactjs webpack web-config semantic-ui package.json


    【解决方案1】:

    您需要做一些事情。确保您已使用 ~ 从 node_modules 导入 CSS,例如:

    import '~semantic-ui-css/semantic.min.css';
    

    其次,这个 CSS 文件 semantic.min.css 还引用了*.woff 文件。我相信它用于引用外部字体文件。您需要 url-loaderfile-loader 来处理这些类型的文件。 url-loader 的示例加载器配置如下所示:

    {
        test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
        loader: 'url-loader',
        options: {
            limit: 10000,
        },
    }
    

    更多文档: url-loader file-loader

    【讨论】:

    • 我做了这个并且它工作了 -> 留下一个错误,说 ERROR in ./node_modules/semantic-ui-css/semantic.min.css Module parse failed: C:\Users\Shawn \Documents\GitHub\Galavue\Galavue\node_modules\semantic-ui-css\semantic.min.css 意外字符 '@' (11:0) 您可能需要适当的加载程序来处理此文件类型。试图在自动取款机上解决问题。
    • { 测试:/\.css$/,使用:['style-loader', 'css-loader', 'resolve-url-loader'],包括:[ path.join(__dirname , 'src'), /node_modules/ ], },解决了我的 @ 错误问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    相关资源
    最近更新 更多