gatsby: WebpackError: TypeError: merge is not a function (from plugin: gatsby-plugin-react-helmet)

Preliminary Checks

Description

When updating to the latest Gatsby releases (3.14.0 or next) builds are failing with the following error:

Building static HTML failed for path "/tags/cryptocurrency/" πŸ‘ˆ this is random

See our docs page for more info on this error: https://gatsby.dev/debug-html


  100 |   }
  101 |
> 102 |   return merge(a, b, { arrayMerge: combineMerge })
      |          ^
  103 | }
  104 |
  105 | export default async function staticPage({


  WebpackError: TypeError: merge is not a function (from plugin: gatsby-plugin-react-helmet)

Reproduction Link

.

Steps to Reproduce

 babel-preset-gatsby              1.13.0  β†’  1.14.0     
 gatsby                           3.13.1  β†’  3.14.0     
 gatsby-plugin-feed               3.13.0  β†’  3.14.0     
 gatsby-plugin-gatsby-cloud        3.1.0  β†’   3.2.0     
 gatsby-plugin-google-tagmanager  3.13.0  β†’  3.14.0     
 gatsby-plugin-image              1.13.0  β†’  1.14.0     
 gatsby-plugin-manifest           3.13.0  β†’  3.14.0     
 gatsby-plugin-react-helmet       4.13.0  β†’  4.14.0     
 gatsby-plugin-sharp              3.13.0  β†’  3.14.0     
 gatsby-plugin-sitemap             4.9.0  β†’  4.10.0     
 gatsby-source-filesystem         3.13.0  β†’  3.14.0     
 gatsby-source-wordpress          5.13.0  β†’  5.14.0     
 gatsby-transformer-sharp         3.13.0  β†’  3.14.0

Expected Result

Should build

Actual Result

Doesn’t build

Environment

System:
    OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
  npmPackages:
    gatsby: 3.13.1 => 3.13.1
    gatsby-plugin-eslint: 4.0.0 => 4.0.0
    gatsby-plugin-feed: 3.13.0 => 3.13.0
    gatsby-plugin-gatsby-cloud: 3.1.0 => 3.1.0
    gatsby-plugin-google-tagmanager: 3.13.0 => 3.13.0
    gatsby-plugin-image: 1.13.0 => 1.13.0
    gatsby-plugin-manifest: 3.13.0 => 3.13.0
    gatsby-plugin-netlify: 3.14.0 => 3.14.0
    gatsby-plugin-react-helmet: 4.13.0 => 4.13.0
    gatsby-plugin-react-helmet-canonical-urls: 1.4.0 => 1.4.0
    gatsby-plugin-react-i18next: 1.1.1 => 1.1.1
    gatsby-plugin-sharp: 3.13.0 => 3.13.0
    gatsby-plugin-sitemap: 4.9.0 => 4.9.0
    gatsby-plugin-theme-ui: 0.11.2 => 0.11.2
    gatsby-source-filesystem: 3.13.0 => 3.13.0
    gatsby-source-google-spreadsheets: 3.0.8 => 3.0.8
    gatsby-source-wordpress: 5.13.0 => 5.13.0
    gatsby-source-youtube-v3: 3.0.2 => 3.0.2
    gatsby-transformer-sharp: 3.13.0 => 3.13.0

Config Flags

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 16
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Another temporary solution is adding explicitely deepmerge dependency to your project.

Another temporary solution is adding explicitly deepmerge dependency to your project.

add deepmerge dependency and it worked

Thanks @pdeszynski

I just upgraded to Gatsby 4, this is still broken. Not sure why it’s closed? @LekoArts

Unfortunately switching from npm to yarn is not an option for me.

I submitted a PR https://github.com/formium/formik/pull/3353 to bump formik’s version of deepmerge.

I reverted to gatsby 3.13.1 for the meantime.

Debugging Screenshots

Reproduction Link ekon97/Gatsby-WebpackError-Merge Steps to Reproduce

  1. npm install
  2. gatsby build

I’ve removed the package-lock.json file, removed the flags inside gatsby-config.js, did a yarn and run gatsby build and it works all fine:

image

When I use your exact setup with the lock file + flags I also get the error:

image

When I then check the installed version of deepmerge I see:

Gatsby-WebpackError-Merge on ξ‚  main is πŸ“¦ v1.0.0 via β¬’ v14.17.6
➜ npm ls deepmerge
bikifi@1.0.0 /home/lennart/development/playground/Gatsby-WebpackError-Merge
β”œβ”€β”¬ @wordpress/block-library@6.0.0
β”‚ └─┬ @wordpress/components@17.0.0
β”‚   └─┬ react-dates@17.2.0
β”‚     └─┬ react-with-styles@3.2.3
β”‚       └─┬ react-with-direction@1.3.1
β”‚         └── deepmerge@1.5.2
β”œβ”€β”¬ gatsby@3.14.0
β”‚ └── deepmerge@4.2.2
└─┬ gatsby-plugin-sharp@3.14.0
  └─┬ probe-image-size@6.0.0
    └── deepmerge@4.2.2

In node_modules you can see that 1.5.2 is installed, not 4.2.2:

image


Your usage of @wordpress/block-library@6.0.0 and its usage of this old deepmerge package is at fault. I’ve tried deleting package-lock.json and doing a fresh install but it still fails. As often, yarn seems to be smarter here as it dedupes to the latest version:

Gatsby-WebpackError-Merge on ξ‚  main [✘?] is πŸ“¦ v1.0.0 via β¬’ v14.17.6 took 1m 5s
➜ yarn why deepmerge
yarn why v1.22.5
[1/4] Why do we have the module "deepmerge"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "deepmerge@4.2.2"
info Has been hoisted to "deepmerge"
info Reasons this module exists
   - Hoisted from "gatsby#deepmerge"
   - Hoisted from "gatsby-plugin-sharp#probe-image-size#deepmerge"
info Disk size without dependencies: "56KB"
info Disk size with unique dependencies: "56KB"
info Disk size with transitive dependencies: "56KB"
info Number of shared dependencies: 0
=> Found "react-with-direction#deepmerge@1.5.2"
info This module exists because "@wordpress#block-library#@wordpress#components#react-dates#react-with-styles#react-with-direction" depends on it.
info Disk size without dependencies: "44KB"
info Disk size with unique dependencies: "44KB"
info Disk size with transitive dependencies: "44KB"
info Number of shared dependencies: 0
Done in 0.60s.

In https://github.com/gatsbyjs/gatsby/pull/33051 we’ve added deepmerge to our dependencies and you now might see this if a third-party library is using an outdated version. You can open an issue on the repository of that third-party library, send in a PR or use yarn resolutions to force the correct version.

Sadly there’s not much more that we can do, that’s just npm and its ecosystem 🀷

using npm install deepmerge then building again worked for me πŸš€

This issue is in Gatsby new version, i switch back to 3.11.1 & it is resolved.

Hi,

I have the same issue as well.

Reproduction Link

https://github.com/ekon97/Gatsby-WebpackError-Merge

Steps to Reproduce

  1. npm install
  2. gatsby build