skip to Main Content

I have trying to add react in the shopify theme. So configured react, webpack, babel manually.
Webpack.dev.js

const merge  = require('webpack-merge');
const common = require("./webpack.common.js")

module.exports = merge(common, {
  mode: "development",
  devtool: "inline-source-map",
  watch: true
})

But I am getting error, merge is not a function.
Thanks in advance.

5

Answers


  1. In a new version of webpack-merge, It is imported like below.

    const { merge } = require('webpack-merge');
    
    Login or Signup to reply.
  2. I use a ES6 webpack config, so I use [email protected]

    import merge from "webpack-merge"
    
    Login or Signup to reply.
  3. As from version 5 of webpack-merge, the merge function is now named export instead of a default export.

    Before version 5

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

    From version 5

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

    If you are using ES modules, then you should do as:

    import { merge } from "webpack-merge"
    
    Login or Signup to reply.
  4. you can also leverage merge by renaming it like below:

    const { merge: webpackMerge } = require("webpack-merge");
    

    by this way you still using the same name of old api of the package!

    Login or Signup to reply.
  5. I have imported like below,

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

    and used as

    const mergedConfig = merge(config, customConfig);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search