使用Webpack编译Babel'decorators'插件时出错

时间:2018-11-02 20:39:34

标签: webpack babel

我收到一个webpack编译错误

Module build failed: Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'.

我尝试添加['@babel/plugin-transform-runtime', { decoratorsBeforeExport: true }]作为错误消息的说明,但是我仍然遇到相同的错误。这是我的webpack配置的babel部分

module: {
    rules: [
        {
            test: /\.js$/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                    '@babel/preset-env',
                    '@babel/preset-stage-0', 
                ],
                plugins: [
                    'transform-class-properties',
                    '@babel/plugin-transform-runtime'
                ]
            }
        },
        exclude: /node_modules/,
        }
    ]
},
plugins: [
    new UglifyJsPlugin({
        sourceMap: true
    })
]

1 个答案:

答案 0 :(得分:1)

通过一遍一遍地尝试选项/插件,而其他所有注释都被排除,我发现了罪魁祸首是IActionWithPayload<T>。我还发现,使用babel 7+,您不需要IAction,因此我将其删除,现在可以使用了。工作设置为:

@babel/preset-stage-0