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

时间:2016-02-21 09:58:58

标签: javascript webpack babeljs jsx

我试图用webpack构建项目,但是我收到了错误。我能够早先用gulp构建这个项目,所以所有路径和一切都应该没问题。我从本文档https://github.com/babel/babel-loader安装了所有babel加载器并复制了示例中的代码。



ERROR in ./src/app.jsx
Module parse failed: ..path../src/app.jsx Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import React from 'react';
| import ReactDom from 'react-dom';
 @ multi main




我的webpack.config文件:



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

module.exports = {
    devtools: 'inline-source-map',
    entry: [
        './src/app.jsx'
    ],
    output: {
        path: '../app/www/js/',
        filename: 'bundle.js'
    },
    resolve: {
        modulesDirectories: [path.join(__dirname, 'node_modules')],
        extensions: ['', '.js', '.jsx', '.scss']
    },
    modules: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['react', 'es2015']
                }
            },
            {
                test: /\.scss$/,
                exclude: /(node_modules|bower_components)/,
                loaders: ["style", "css", "sass"]
            }
        ]
    }
};




1 个答案:

答案 0 :(得分:1)

应该是vals,而不是loader: 'babel'

编辑:显然他们是等同的。问题出在Webpack配置文件中,它是loader: 'babel-loader',而不是module