webpack2 不能解析import等语法

当我把babel的modules: false时开始webpack会出现以下错误,不是支持import的吗?为什么海报错呢

ERROR in ./js/src/Unique_main.jsx
Module build failed: ReferenceError: [BABEL] /Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/js/src/Unique_main.jsx: Using removed Babel 5 option: foreign.modules – Use the corresponding module transform plugin in the plugins option. Check out http://babeljs.io/docs/plugins/#modules
at Logger.error (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/logger.js:41:11)
at OptionManager.mergeOptions (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/options/option-manager.js:216:20)
at /Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/options/option-manager.js:260:14
at /Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/options/option-manager.js:329:22
at Array.map (native)
at OptionManager.resolvePresets (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/options/option-manager.js:270:20)
at OptionManager.mergePresets (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/options/option-manager.js:259:10)
at OptionManager.mergeOptions (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/options/option-manager.js:244:14)
at OptionManager.init (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/options/option-manager.js:374:12)
at File.initOptions (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/index.js:216:65)
at new File (/Applications/XAMPP/xamppfiles/htdocs/woeks/20161115/SmartAnalysis/node_modules/babel-core/lib/transformation/file/index.js:139:24)

这是我的配置信息


var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");  //CSS 模块加载
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        build: [
            // 'react-hot-loader/patch',
            'webpack-dev-server/client?http://127.0.0.1:3001',
            'webpack/hot/dev-server',
            "./js/src/Unique_main.jsx"
        ]
    },
    output: {
        path: path.resolve(__dirname, 'js/dist'),
        // path: __dirname,
        filename: "bundle.js",
        publicPath: '/assets/',
        chunkFilename: '[name].[chunkhash:10].chunk.js',
    },
   plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new ExtractTextPlugin({
                filename: "Respectively.css",
                disable: false,
                allChunks: true
        }),
       new HtmlWebpackPlugin({ title: 'Tree-shaking' })
    ],
    module: {
        // loaders:[
        rules: [
            { 
                test: /\.jsx$/,
                exclude: /node_modules/,
                // loader: 'babel-loader',
                use:[
                    // {loader:'react-hot-loader'},
                    {
                        loader:"babel-loader",
                        options: {
                            presets:['es2015', { modules: false }, 'stage-2', 'react'],
                            //按需加载模块,antd...
                            plugins:[["import",[
                                {
                                    "libraryName": "antd",
                                    "libraryDirectory": "lib",
                                    "style":true
                                },
                                {
                                    "libraryName": "antd-mobile",
                                    "libraryDirectory": "component",
                                },
                            ]],
                                "transform-decorators-legacy",
                                "transform-class-properties"
                            ]
                        }
                    },
                ]
            },
            // {
            //     test:/.*/,
            //     include: [path.resolve(__dirname, './js/src/components/pipe')],
            //     loader: 'bundle?lazy&name=pipe'
            // },
            {
                test:/\.css$/,
                exclude:/node_modules/,
                use:ExtractTextPlugin.extract({
                     fallback: "style-loader",
                     use:["css-loader"]
                     // publicPath: "/dist"
                })
            },
            {
                test:/\.(png|jpg|svg)$/,
                use:['file-loader'],
            },
            {
                test:/\.less$/,
                use:['style-loader','css-loader','less-loader']
            },
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx'],
    },
}

Author: Fantashit

1 thought on “webpack2 不能解析import等语法

  1. It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I’m closing this. Please either update the issue with the template and reopen, or open a new issue.

    Please write in english here!

Comments are closed.