简体   繁体   English

Webpack错误:“您可能需要适当的加载程序来处理此文件类型”

[英]Webpack error: “You may need an appropriate loader to handle this file type”

I get the following error " You may need appropriate loader to handle this file type " while using Webpack to compile ES6 and JSX files. 我在使用Webpack编译ES6和JSX文件时收到以下错误“ 您可能需要适当的加载程序来处理此文件类型 ”。

Terminal ERROR: 终端错误:

You may need an appropriate loader to handle this file type.
| import React from 'react';
| import ReactDOM from 'react-dom';

webpack.config.js looks like this, webpack.config.js看起来像这样,

module.exports = {
    entry: './main.js',
    output: {
        path: './',
        filename: 'index.js'
    },
    devServer: {
        inline: true,
        port: 2525
    },
    module: {
        loaders: [
            {
                test: '/\.js$/',
                exclude: /node_modules/,
                loader: 'babel-loader'
                query: {
                    presets: ['es2015','react']
                }
            }
        ]
    }
}

main.js file contains, main.js文件包含,

import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
    render(){
        return <h1>Title text</h1>
    }
}
ReactDOM.render(<App/>,document.getElementById('app'));

package.json looks like this, package.json看起来像这样,

{
  "name": "react-webpack-es6",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^0.14.7",
    "react-dom": "^0.14.7"
  },
  "devDependencies": {
    "babel-core": "^6.7.4",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "webpack": "^1.12.14",
    "webpack-dev-server": "^1.14.1"
  }
}

Let me know if I'm missing something here. 让我知道我是否在这里错过了什么。

In webpack.config.js , the test property in module.loaders should be a regular expression, not a string. webpack.config.js ,在test中性能module.loaders应该是一个正则表达式,而不是一个字符串。

module: {
  loaders: [{
    test: '/\.js$/',

change this '/\\.js$/' to this /\\.js$/ 将此'/\\.js$/'更改为/\\.js$/

module: {
  loaders: [{
    test: /\.js$/,

Know more at webpack/module-loaders 进一步了解webpack / module-loaders

暂无
暂无

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

相关问题 webpack错误-您可能需要适当的加载程序来处理此文件类型 - error with webpack - 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 和 Babel “你可能需要一个合适的加载器来处理这种文件类型” - "You may need an appropriate loader to handle this file type" with Webpack and Babel Webpack和Babel的“您可能需要适当的加载器来处理此文件类型” - “You may need an appropriate loader to handle this file type” with Webpack and Babel ReactJS,Webpack:您可能需要适当的加载器来处理此文件类型 - ReactJS ,Webpack : You may need an appropriate loader to handle this file type React webpack 错误:您可能需要适当的加载程序来处理此文件类型,目前没有配置加载程序来处理此文件 - React webpack error: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file webpack错误:模块解析失败您可能需要适当的加载程序来处理此文件类型 - webpack Error :Module parse failed You may need an appropriate loader to handle this file type Babel Webpack错误:您可能需要适当的加载程序来处理此文件类型 - Babel Webpack Error: You may need an appropriate loader to handle this file type 通过Webpack导入节点模块时出错,“您可能需要适当的加载程序来处理此文件类型” - Error importing node module through Webpack, “You may need an appropriate loader to handle this file type” Webpack错误:您可能需要适当的加载程序来处理此文件类型。 | @字符集“ UTF-8”; - Webpack error: You may need an appropriate loader to handle this file type. | @charset “UTF-8”;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM