graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

SyntaxError: Named export 'OperationTypeNode' not found. The requested module 'graphql' is a CommonJS module, which may not support all module.exports as named exports.

Open sobolk opened this issue 5 months ago • 6 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • [ ] 2. A failing test has been provided
  • [ ] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

The release today (https://github.com/ardatan/graphql-tools/releases/tag/release-1752755436363) seems to be regressing ESM based projects.

Our canary tests have started failing at the moment release shipped with the following error:

bcd0740fa72c:testapp110 sobkamil$ npx ampx sandbox --once
file:///Users/sobkamil/playground/testapp110/node_modules/@graphql-codegen/core/node_modules/@graphql-tools/merge/node_modules/@theguild/federation-composition/esm/subgraph/state.js:1
import { Kind, OperationTypeNode, specifiedScalarTypes, DirectiveLocation, } from "graphql";
               ^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'OperationTypeNode' not found. The requested module 'graphql' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'graphql';
const { Kind, OperationTypeNode, specifiedScalarTypes, DirectiveLocation, } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:175:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:258:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

It seems that update of @theguild/federation-composition mentioned in the release might be causing this.

To Reproduce Steps to reproduce the behavior:

I was able to repro this using our product. We depend on you trasitively.

mkdir testapp110
cd testapp110
npm create amplify@latest
npx ampx sandbox --once

I have also created somewhat standalone repro here https://github.com/sobolk/testapp110 . See README.

Expected behavior

The ESM loader error is not present.

Environment:

  • OS: OSX
  • @graphql-tools/...:
  • NodeJS:

Additional context

sobolk avatar Jul 17 '25 17:07 sobolk

A fix has been deployed as of Jul 21 https://github.com/ardatan/graphql-tools/releases/tag/release-1753069150397 in @graphql-tools/[email protected]. Please let us know if this completely resolved the issue for you.

jdolle avatar Jul 23 '25 16:07 jdolle

Probably relates to https://github.com/ardatan/graphql-tools/pull/7229 which introduces this new dependancy and that requires graphql v16 (so doesn't work with v15)

I pinned these to fix it for us:

        "@graphql-tools/graphql-file-loader": "8.0.20",
        "@graphql-tools/load": "8.1.2",

wtfiwtz avatar Oct 08 '25 22:10 wtfiwtz

We removed that dependency already in https://github.com/ardatan/graphql-tools/pull/7298 You mean updating it doesn't fix your issue?

ardatan avatar Oct 08 '25 22:10 ardatan

I'm seeing the same problem with the following dependencies

✗ pnpm why @theguild/federation-composition
Legend: production dependency, optional only, dev only

graphql-config 5.1.2
└─┬ @graphql-tools/graphql-file-loader 8.1.2
  └─┬ @graphql-tools/import 7.1.2
    └── @theguild/federation-composition 0.20.1

@graphql-tools/graphql-file-loader 8.1.3
└─┬ @graphql-tools/import 7.1.3
  └── @theguild/federation-composition 0.20.2

tarasvalstro avatar Oct 31 '25 12:10 tarasvalstro

@jdolle Could you take a look?

ardatan avatar Oct 31 '25 14:10 ardatan

I found the issue but I'd like input for the best way to resolve it. The issue is, as you stated, that the federation-composition is still being used by one of the packages. And this library only supports graphql v16

Some options for resolution are:

  1. We could optionally support older versions of graphql in the federation-composition library
  2. We could do a major version bump and officially drop older versions of graphql from graphql-tools
  3. or we figure out a workaround, similar to https://github.com/ardatan/graphql-tools/pull/7298, but for the graphql-tools/import .. This is my personal least favorite because it involves more duplicating of logic that exists elsewhere.

From a convenience perspective to consumers of this package, I could see supporting older versions of graphql being nice. But v16 has been available for 4 years. I'm not sure why other libraries haven't been updated as of yet and why we have to continue to support these prior versions.

jdolle avatar Nov 07 '25 22:11 jdolle