从 webpack-cli 获取错误:“TypeError:merge is not a function";在 webpack 配置中 [英] Getting Error from webpack-cli: "TypeError: merge is not a function" in webpack config

查看:143
本文介绍了从 webpack-cli 获取错误:“TypeError:merge is not a function";在 webpack 配置中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 webpack-merge 将两个 webpack.config 文件组合在一起,但我不断收到错误消息"TypeError: merge is not a function when I run the command "webpack --config ./config/webpack.config.prod.js"

I'm using webpack-merge to combine two webpack.config files together but I keep getting the error "TypeError: merge is not a function when I run the command "webpack --config ./config/webpack.config.prod.js"

有其他人遇到过这个问题吗?

Has anybody else run across this issue?

webpack.config.prod.js

webpack.config.prod.js

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
const TerserPlugin = require('terser-webpack-plugin');
const commonConfig= require('./webpack.config.common');
const merge = require('webpack-merge');

module.exports = merge(commonConfig, {

    //config code
 
})

推荐答案

您导入的 merge 不正确.像这样尝试:

You are importing merge incorrectly. Try it like this:

const { merge } = require('webpack-merge');

UPD:基于 aa>,从 webpack-merge 5.0.3 及更高版本开始,你应该使用我上面提供的代码.如果版本低于5.0.3,则需要使用:

UPD: Based on the following changelog, starting with webpack-merge 5.0.3 and higher, you should use the code I provided above. If the version is lower than 5.0.3, then you need to use:

const merge = require('webpack-merge');

这篇关于从 webpack-cli 获取错误:“TypeError:merge is not a function";在 webpack 配置中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆