gatsby: [v2] Error: Cannot find module 'core-js/modules/es6.array.filter'

Description

gatsby develop returns the above error

Steps to reproduce

I upgraded a site from v2 to v2 by copying my dependencies, modules & pages over and following the guide here: https://next.gatsbyjs.org/docs/migrating-from-v1-to-v2/

Environment

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 8.11.3 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.4.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 68.0.3440.106
    Safari: 11.1.2
  npmPackages:
    gatsby: 2.0.0-rc.9 => 2.0.0-rc.9 
    gatsby-plugin-canonical-urls: ^2.0.0-rc.1 => 2.0.0-rc.1 
    gatsby-plugin-google-tagmanager: ^2.0.0-rc.1 => 2.0.0-rc.1 
    gatsby-plugin-manifest: next => 2.0.2-rc.1 
    gatsby-plugin-offline: next => 2.0.0-rc.2 
    gatsby-plugin-react-helmet: ^3.0.0-rc.1 => 3.0.0-rc.1 
    gatsby-plugin-remove-trailing-slashes: ^2.0.0-rc.1 => 2.0.0-rc.1 
    gatsby-plugin-robots-txt: ^1.3.0 => 1.3.0 
    gatsby-plugin-sitemap: ^2.0.0-rc.1 => 2.0.0-rc.1 
    gatsby-plugin-styled-components: ^3.0.0-rc.1 => 3.0.0-rc.1 
    gatsby-source-apiserver: ^1.3.1 => 1.3.1 
    gatsby-source-filesystem: ^2.0.1-rc.1 => 2.0.1-rc.1 
    gatsby-source-wordpress: ^3.0.0-rc.1 => 3.0.0-rc.1 
    gatsby-transformer-javascript-frontmatter: ^2.0.0-rc.2 => 2.0.0-rc.2 
    gatsby-transformer-json: ^2.1.1-rc.1 => 2.1.1-rc.1 
  npmGlobalPackages:
    gatsby-cli: 1.1.58

I’ve tried installing babel-preset-env and deleting node_modules & reinstalling.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 26 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks Pieh yeah tried that, no go I’m afraid.

I did actually just fix this by running npm install --save core-js

Can you try deleting lock files (yarn.lock / package-lock.json) and node_modules and reinstalling again?

I had the same issue.

Downgrading my core-js version to 2.6.5 (dev-dependency) fixed it.

@secretfader You can add @babel/polyfill to your devDependencies, it’ll automatically load necessary core-js polyfills. Make sure to delete your node_modules folder and possibly your package-lock.json file and run npm install to start with a clean resolved dependency tree.

Adding "@babel/polyfill": "^7.0.0", and following those instructions didn’t work for me. Adding core-js did work npm install --save core-js.

<strike>npm install --save core-js</strike> no longer works.

Use npm install --save --dev core-js@2.6.5 instead.

However, try running npm install --dev core-js@2.6.5 in the project’s directory so that you do not save it globally.

@secretfader You can add @babel/polyfill to your devDependencies, it’ll automatically load necessary core-js polyfills. Make sure to delete your node_modules folder and possibly your package-lock.json file and run npm install to start with a clean resolved dependency tree.

@ben-rogerson I should have updated my comment, because the error occurred again after I removed my package-lock.json. It looks like the dependencies haven’t been resolved correctly, but ironically it worked after doing so. Sometimes npm is a mystery of rainbow unicorns 🙄 Also in mdx-js/mdx#271 the maintainer posted it didn’t worked with npm, but when using yarn everything run fine.

I’ll play around with the results when adding core-js or @babel/polyfill as dependency, but I’m curious why it works afterwards since core-js is already resolved through gatsby and without explicitly importing the polyfill in the code I don’t see any difference between the devDependencies solution.

I can reproduce the issue. If you are looking for a reproduction repository, https://github.com/mui-org/material-ui/blob/master/examples/gatsby/README.md is a good one.

If the previous doesn’t work, use:

npm install --save core-js@2.6.5 -g

Installing such packages globally is a really bad idea and there’s no reason to do so. If you’e having problems when installed locally (with pinned version), it might be because you’ve already installed other packages globally that causing conflicts now. I guess the main problem of this ticket is npm. It seems like it doesn’t resolve the dependency tree correct. I’ve switched to yarn last year (mainly because of workspaces) and never had problems again. I guess npm users need to use the workaround by pinning the version and hope that npm 8 (that’ll be powered by their new tink lib, announced in their npm Roadmap Summer 2019 blog post) fixes such problems (or switch to yarn for Gatsby based projects).

Thanks Pieh yeah tried that, no go I’m afraid.

I did actually just fix this by running npm install --save core-js

Got it working thanks to this!

Pieh I had the same issue and I pinpointed it to babel removing the core-js dependency in their 7.0.0 beta versions, before they put it up again in their final version.