繁体   English   中英

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

[英]webpack ERROR :You may need an appropriate loader to handle this file type

我尝试了很多方法,我搜索了stackoverflow,仍然无法解决。 我是个新手。

错误 :

ERROR in ./public/js/index.jsx
Module parse failed: /home/m/react/r-chat/front/public/js/index.jsx Line  3: Unexpected token
You may need an appropriate loader to handle this file type.
| /*'use strict';*/
| 
| import React, { Component, ProTypes } from 'react';
| import { Router, Route, IndexRoute, browserHistory, hashHistory } from   'react-router';
| import Avatar from './components/avatar.jsx';

和我的webpack文件:

var webpack = require('webpack');

module.exports = {
    entry:  './public/js/index.jsx',
    output: {
    path: './build',
    filename: "bundle.js"
},
module: {
    loaders: [
        {
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel',
            query: {
                presets: ['es2015','react']
            }
        }
    ]
},
plugins: [
    new webpack.NoErrorsPlugin()
]
};

您需要一个.jsx加载程序。 由于您使用的是.jsx文件,因此.js加载程序将无法正常运行。

更改

{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel',
            query: {
                presets: ['es2015','react']
            }
        }

{
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel',
            query: {
                presets: ['es2015','react']
            }
        }

您在正在测试js的webpack配置的加载程序中看到了吗? 您需要为JSX添加它,并使用适当的加载器。

babel可以通过babel-loader为您做到这一点: https : //github.com/babel/babel-loader

您需要做的就是将x插入测试,如下所示:

loaders: [
    {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
            presets: ['es2015','react']
        }
    }
]

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM