Error: Cannot find module ‘gatsby-plugin-utils/polyfill-remote-file’

After updating Gatsby from 3.0.4 to 4.12.1 I got the following error message: Error: Cannot find module 'gatsby-plugin-utils/polyfill-remote-file' and the stack trace below:

$ NODE_OPTIONS="-r esm" gatsby develop -H 0.0.0.0 -o
/Users/esausilva/Development/Projects/andreasilva-design/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

/Users/esausilva/Development/Projects/andreasilva-design/node_modules/gatsby/dist/utils/start-server.js:1
Error: Cannot find module 'gatsby-plugin-utils/polyfill-remote-file'
Require stack:
- /Users/esausilva/Development/Projects/andreasilva-design/node_modules/gatsby/dist/utils/start-server.js
...

This is because Gatsby now natively supports ES6 Module Syntax in Gatsby API and I had the following in my package.json, adding support manually for ESM when building.

{
  "scripts": {
    "build": "NODE_OPTIONS=\"-r esm\" gatsby build",
    "develop": "NODE_OPTIONS=\"-r esm\" gatsby develop -H 0.0.0.0 -o",
    "serve": "NODE_OPTIONS=\"-r esm\" gatsby serve"
  }
}

More specifically NODE_OPTIONS=\"-r esm\" option

Fixing ES6 Module Error in Gatsby

Rename your gatsby-node.js to gatsby-node.esm.js, create a new file named gatsby-node.js and add the following

// gatsby-node.js

const requireEsm = require('esm')(module);
module.exports = requireEsm('./gatsby-node.esm.js');

Fix your package.json scripts

  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop -H 0.0.0.0 -o",
    "serve": "gatsby serve"
  },

For the official documentation follow: https://support.gatsbyjs.com/hc/en-us/articles/1500000294121-Using-ES6-Module-Syntax-in-Gatsby-API-Files-on-Gatsby-Cloud

[bottomads][/bottomads]

Spread the love

One thought on “Error: Cannot find module ‘gatsby-plugin-utils/polyfill-remote-file’

  1. whoiscall says:

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.