Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to fix compatibility with Gatsby and our Apollo fix to use ESM #114

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eric-burel
Copy link
Contributor

@eric-burel eric-burel commented Sep 15, 2022

Current state of things:

Repro:

  • pnpm install
  • cd results && pnpm run build
  • won't work

Stuck at:

Error: [ERR_REQUIRE_ESM]: require() of ES Module /code/devographics/monorepo/node_modules/.pnpm/@[email protected][email protected]/node_modules/@apollo/client/index.js from /code/devographics/monorepo/node_modules/.pnpm/@[email protected]_@[email protected]/node_
  modules/@graphql-tools/links/cjs/createServerHttpLink.js not supported.
  Instead change the require of index.js in /code/devographics/monorepo/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@graphql-tools/links/cjs/createServerHttpLink.js to a dynamic import() which is available in all CommonJS modules.
  
  - createServerHttpLink.js:6 Object.<anonymous>
    [monorepo]/[@[email protected]_@[email protected]]/[@graphql-tools]/links/cjs/createServerHttpLink.js:6:43

This is probably because gatsby-source-graphql is not using ESM. It then uses the CJS version of @graphql-tools/links, which however will somehow try to load the ESM version of Apollo Client when we apply our patch

If I remove "type":"module" from Apollo Client package.json, I still hit:

  Error: /code/devographics/monorepo/node_modules/.pnpm/@[email protected][email protected]/node_modules/@apollo/client/index.js:1
  export * from "./core/index.js";
  ^^^^^^
  SyntaxError: Unexpected token 'export'

If I remove "type": "module" and the patched export map:


  Error: [ERR_REQUIRE_ESM]: require() of ES Module /code/devographics/monorepo/node_modules/.pnpm/[email protected]/node_modules/ts-invariant/lib/invariant.js from /code/devographics/monorepo/node_modules/.pnpm/@[email protected][email protected]/node_modules/@apollo/client
  /utilities/globals/globals.cjs not supported.
  Instead change the require of invariant.js in /code/devographics/monorepo/node_modules/.pnpm/@[email protected][email protected]/node_modules/@apollo/client/utilities/globals/globals.cjs to a dynamic import() which is available in all CommonJS modules.

This is because we also patch "ts-invariant".

So basically I have to remove the patch altogether to have no exports map in Apollo Client, but then that breaks the ESM build of Next.js when using Vulcan packages.

Best solution might be to rewrite "gatsby-source-graphql" to not use Apollo client. Apollo is most probably very overkill here, any graphql lib that works server side and that has basic caching should work.

@vercel
Copy link

vercel bot commented Sep 15, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
surveyform ✅ Ready (Inspect) Visit Preview Sep 15, 2022 at 8:24AM (UTC)

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for stateofgraphql2022 failed.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/stateofgraphql2022/deploys/6322dfc7474bf8000c586aa2

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for stateofcss canceled.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/stateofcss/deploys/6322dfc7063d7b0008f7ee9e

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for stateofjs2021 failed.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/stateofjs2021/deploys/6322dfc7821a1500088ba3a0

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for stateofjs canceled.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/stateofjs/deploys/6322dfc7486b2b0008c1b20e

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for stateofcss2021 failed.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/stateofcss2021/deploys/6322dfc780175300085fe18f

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for devographics-static failed.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/devographics-static/deploys/6322dfc7f0f9dc000936d597

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for state-of-graphql canceled.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/state-of-graphql/deploys/6322dfc76055320009726041

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for graphiql-devographics canceled.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/graphiql-devographics/deploys/6322dfc701167000086d9053

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for devographics-graphiql-internal canceled.

Name Link
🔨 Latest commit fdb6c5e
🔍 Latest deploy log https://app.netlify.com/sites/devographics-graphiql-internal/deploys/6322dfc7b09d9200090533c8

@gatsby-cloud
Copy link

gatsby-cloud bot commented Sep 15, 2022

❌ js2021 deploy preview failed

Your build failed. View the build logs.

@gatsby-cloud
Copy link

gatsby-cloud bot commented Sep 15, 2022

❌ State of GraphQL 2022 deploy preview failed

Your build failed. View the build logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant