简体   繁体   English

CSS - 您可能需要适当的加载程序来处理此文件类型

[英]CSS - You may need an appropriate loader to handle this file type

In my App.jsx file I am importing a css file like this: import './App.css';在我的App.jsx文件中,我正在导入一个 css 文件,如下所示: import './App.css';

I have the following code in my webpack.config.js .我的webpack.config.js中有以下代码。

var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname, 'src/build');
var APP_DIR = path.resolve(__dirname, 'src/app');

var config = {
  entry: APP_DIR + '/App.jsx',
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  },
  module : {
    loaders : [
    {
      test: /\.scss$/,
      include : APP_DIR,
      loaders : ["style", "css", "sass"]
    },
    {
      test : /\.jsx?/,
      include : APP_DIR,
      loader : 'babel'
    }
   ]
  }
};

module.exports = config;

Since I have a loader for css, everything seems alright.因为我有一个 css 的装载机,所以一切似乎都很好。

However, I am getting:但是,我得到:

ERROR in ./src/app/App.css
Module parse failed: /path/to/file/App.css Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:0)

You only have a scss loader setup so once its hitting a css file it doesn't know how to parse. 你只有一个scss加载器设置,所以一旦它命中一个css文件,它就不知道如何解析。

{ test: /\\.css$/, loader: "style-loader!css-loader" }

should get you up and going. 应该让你起来。

Edit: 编辑:

Also if you are using scss why not just change App.css to App.scss that way your css type is consistent and don't have to include the css loader. 此外,如果您使用scss,为什么不将App.css更改为App.scss,这样您的css类型是一致的,并且不必包含css加载器。 I would say that is the best solution. 我会说这是最好的解决方案。

In addition to finalfreq's answer , the up-to-date way of doing this is no longer to separate loaders with a !除了finalfreq 的回答之外,最新的做法不再是用! , and to instead include them as an array with use : , 而是将它们作为一个数组包含在use中:

{
  test: /\.css$/,
  use: [
    "style-loader",
    "css-loader"
  ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您可能需要适当的加载程序来处理此文件类型错误 - You may need an appropriate loader to handle this file type-error 您可能需要适当的加载程序来处理此文件类型 - React You may need an appropriate loader to handle this file type Webpack:您可能需要适当的加载器来处理此文件类型 - Webpack: You may need an appropriate loader to handle this file type webpack错误-您可能需要适当的加载程序来处理此文件类型 - error with webpack - You may need an appropriate loader to handle this file type 你可能需要一个合适的加载器来处理这种文件类型的 js - You may need an appropriate loader to handle this file type js glsify - 错误'您可能需要适当的加载程序来处理此文件类型'? - glsify - error 'You may need an appropriate loader to handle this file type'? Webpack 和 Babel “你可能需要一个合适的加载器来处理这种文件类型” - "You may need an appropriate loader to handle this file type" with Webpack and Babel 您可能需要一个合适的加载器来处理这种文件类型。 ReactJs - You may need an appropriate loader to handle this file type. ReactJs “您可能需要适当的加载程序来处理此文件类型” - “You may need an appropriate loader to handle this file type” Webpack和Babel的“您可能需要适当的加载器来处理此文件类型” - “You may need an appropriate loader to handle this file type” with Webpack and Babel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM