directus / gatsby-source-directus

Source plugin for pulling data into Gatsby from a Directus API.
10 stars 12 forks source link

Fix node-fetch version to `^2.6.11` #29

Closed joselcvarela closed 1 year ago

joselcvarela commented 1 year ago

Motivation

In https://github.com/directus/gatsby-source-directus/pull/26 it was added a feature to retry requests. This feature depends on node-fetch so it was installed the latest version of this package. Although version 3.x of node-fetch is ESM only and when trying to run gatsby develop the following error appears:

  Error: [ERR_REQUIRE_ESM]: require() of ES Module /tmp/gatsby-directus/node_modules/.pnpm/node-fetch@3.3.1/node_modules/node-fetch/src/index.js from /private/tmp/gatsby-directus/node_modules/.pn
  pm/@directus+gatsby-source-directus@9.16.0_eslint@8.44.0_gatsby-source-filesystem@5.11.0_gatsby-source-graphql@5.11.0/node_modules/@directus/gatsby-source-directus/gatsby-node.js not supported.
  Instead change the require of index.js in /tmp/gatsby-directus/node_modules/.pnpm/@directus+gatsby-source-directus@9.16.0_eslint@8.44.0_gatsby-source-filesystem@5.11.0_gatsby-source-graphql@5.1
  1.0/node_modules/@directus/gatsby-source-directus/gatsby-node.js to a dynamic import() which is available in all CommonJS modules.

Solution

In https://github.com/directus/gatsby-source-directus/pull/28 there's an attempt to overcome this issue by implementing the dynamic import. Although, the recommended solution for now should be to follow other packages that we depend on like gatsby or gatsby-source-graphql which are using version ^2.6.11 of node-fetch

Closes https://github.com/directus/gatsby-source-directus/pull/28