gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

gatsby-remark-external-links is broken by unist-util-find version 1.0.3 update to ESM #38258

Closed vadimgo closed 1 year ago

vadimgo commented 1 year ago

Preliminary Checks

Description

Due to unist-util-find version 1.0.3 update to ESM, gatsby-remark-external-links is broken resulting in a build error when it is used:

Error: [ERR_REQUIRE_ESM]: require() of ES Module /home/vadim/mauka/my-gatsby-site/node_modules/unist-util-find/index.js from /home/vadim/mauka/my-gatsby-site/node_modu les/gatsby-remark-external-links/index.js not supported. Instead change the require of /home/vadim/mauka/my-gatsby-site/node_modules/unist-util-find/index.js in /home/vadim/mauka/my-gatsby-site/node_modules/gatsby-remark-ext ernal-links/index.js to a dynamic import() which is available in all CommonJS modules.

Reproduction Link

https://github.com/gatsbyjs/gatsby-starter-minimal-ts

Steps to Reproduce

1) npm init gatsby -- -ts

with mdx support enabled

2) npm install gatsby-remark-external-links 3) In gatsby-config.ts replace "gatsby-plugin-mdx" with

{
  resolve: 'gatsby-plugin-mdx',
  options: {
    extensions: ['.md', '.mdx'],
    gatsbyRemarkPlugins: [
      {
        resolve: 'gatsby-remark-external-links',
        options: {
          target: '_blank',
          rel: 'nofollow noopener noreferrer',
        },
      },
    ],
  },
},

4) npm run build 5) Observe the build error

Expected Result

No build error.

Actual Result

Build error:

Error: [ERR_REQUIRE_ESM]: require() of ES Module /home/vadim/mauka/my-gatsby-site/node_modules/unist-util-find/index.js from /home/vadim/mauka/my-gatsby-site/node_modu les/gatsby-remark-external-links/index.js not supported. Instead change the require of /home/vadim/mauka/my-gatsby-site/node_modules/unist-util-find/index.js in /home/vadim/mauka/my-gatsby-site/node_modules/gatsby-remark-ext ernal-links/index.js to a dynamic import() which is available in all CommonJS modules.

Environment

> my-gatsby-site@1.0.0 clipboard
> gatsby info --clipboard

  System:
    OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 18.12.1 - ~/.config/nvm/versions/node/v18.12.1/bin/node
    npm: 9.7.2 - ~/.config/nvm/versions/node/v18.12.1/bin/npm
  npmPackages:
    gatsby: ^5.11.0 => 5.11.0
    gatsby-plugin-emotion: ^8.11.0 => 8.11.0
    gatsby-plugin-image: ^3.11.0 => 3.11.0
    gatsby-plugin-mdx: ^5.11.0 => 5.11.0
    gatsby-plugin-sharp: ^5.11.0 => 5.11.0
    gatsby-plugin-sitemap: ^6.11.0 => 6.11.0
    gatsby-remark-external-links: ^0.0.4 => 0.0.4
    gatsby-source-filesystem: ^5.11.0 => 5.11.0
    gatsby-transformer-sharp: ^5.11.0 => 5.11.0

Config Flags

No response

vadimgo commented 1 year ago

A possible quick fix until a permanent solution would be to fix the dependency of gatsby-remark-external-links to version 1.0.2 of unist-util-find.

LekoArts commented 1 year ago

Hi!

Thanks for the issue! We've updated our packages to use a pinned version, but the plugin you have problems with is a community plugin: https://github.com/JLongley/gatsby-remark-external-links

So you'll have to wait for a 1.0.4 release or use another way of forcing the version.

vadimgo commented 1 year ago

Thank you for the update. For now as a workaround, I've switched from using gatsby-remarl-external-links to remark-exterbal-links via mdxOptions / remarkPlugins when resolving gatsby-plugin-mdx.