【问题标题】:Node: Module parse failed: Unexpected token "You may need an appropriate loader to handle this file type"节点:模块解析失败:意外令牌“您可能需要适当的加载程序来处理此文件类型”
【发布时间】:2019-02-26 04:32:32
【问题描述】:

这是在我的 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};

【问题讨论】:

  • 你的 babelrc 配置是什么?你有其他预设设置为 babel-loader 吗?
  • { "presets": [ ["env", { "modules": false, "targets": { "browsers": ["> 1%", "last 2 versions", "not即
  • 您需要为传播算子预设
  • 您能详细说明一下吗?扩展运算符是什么?非常感谢

标签: node.js webpack


【解决方案1】:

您需要一个插件来转换扩展运算符 (...)。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-12
    • 2022-08-09
    • 2022-11-10
    • 2018-02-27
    • 2019-01-28
    • 2021-02-10
    • 1970-01-01
    • 2021-12-04
    相关资源
    最近更新 更多