节点:模块解析失败:意外的令牌“您可能需要适当的加载程序来处理此文件类型”

时间:2018-09-21 18:22:31

标签: node.js webpack

这是在我的webpack.base.conf.js中

resolve: {
            extensions: ['.js', '.vue', '.json'],
            alias: {
                'vue$': 'vue/dist/vue.esm.js',
                '@': resolve('src'),
            }
        },
        module: {
            rules: [
                {
                    test: /\.(js|vue)$/,
                    loader: 'eslint-loader',
                    enforce: 'pre',
                    include: [resolve('src'), resolve('test')],
                    options: {
                        formatter: require('eslint-friendly-formatter')
                    }
                },
                {
                    test: /\.vue$/,
                    loader: 'vue-loader',
                    options: vueLoaderConfig
                },
                {
                    test: /\.js$/,
                    loader: 'babel-loader',
                    include: [resolve('src'), resolve('test')]
                },

当我使用此行运行webpack时

webpack ./src/main.js --output ./dist

这是完整的错误:

ERROR in ./src/main.js 240:36
Module parse failed: Unexpected token (240:36)
You may need an appropriate loader to handle this file type.
|                 state.connection.lastUpdate = Date.now();
|
>                 state.currencies = {...information.currenciesInfo};
|
|                 state.trends = {...information.trends};

在其他网站上,我读到它可能与webpack或某些机箱问题有关。有人发现明显的问题吗?

我相信程序员使用了webpack3,我从头开始构建了webpack4

感谢输入

编辑:main.js

// information = information[0];
                state.connection.lastUpdate = Date.now();

                state.currencies = {...information.currenciesInfo};

                state.trends = {...information.trends};

1 个答案:

答案 0 :(得分:0)

您需要一个插件来转换传播算子(...)。

使用https://babeljs.io/docs/en/babel-plugin-transform-object-rest-spread