graphql-typed-document-node: Error "The package may have incorrect main/module/exports specified in its package.json."

I tried to upgrade my app to use v3.1.2, but without any other code changes, the following error shows up on build:

Error: Failed to resolve entry for package @graphql-typed-document-node/core. The package may have incorrect main/module/exports specified in its package.json.

Call stack
    at packageEntryFailure (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/vite@4.1.4_@types+node@18.14.1/node_modules/vite/dist/node/chunks/dep-ca21228b.js:22005:11)
    at resolvePackageEntry (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/vite@4.1.4_@types+node@18.14.1/node_modules/vite/dist/node/chunks/dep-ca21228b.js:22002:5)
    at tryNodeResolve (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/vite@4.1.4_@types+node@18.14.1/node_modules/vite/dist/node/chunks/dep-ca21228b.js:21737:20)
    at Object.resolveId (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/vite@4.1.4_@types+node@18.14.1/node_modules/vite/dist/node/chunks/dep-ca21228b.js:21488:28)
    at Object.handler (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/vite@4.1.4_@types+node@18.14.1/node_modules/vite/dist/node/chunks/dep-ca21228b.js:44872:19)
    at file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/rollup@3.17.1/node_modules/rollup/dist/es/shared/node-entry.js:24163:40
    at async PluginDriver.hookFirstAndGetPlugin (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/rollup@3.17.1/node_modules/rollup/dist/es/shared/node-entry.js:24063:28)
    at async resolveId (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/rollup@3.17.1/node_modules/rollup/dist/es/shared/node-entry.js:23007:26)
    at async ModuleLoader.resolveId (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/rollup@3.17.1/node_modules/rollup/dist/es/shared/node-entry.js:23271:15)
    at async Object.resolveId (file:///Users/joulev/dev/www/webapps/node_modules/.pnpm/vite@4.1.4_@types+node@18.14.1/node_modules/vite/dist/node/chunks/dep-ca21228b.js:7972:10)

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 17 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Using @graphql-codegen/client-preset@4.1.0, in the codegen.ts file I added the config for the client preset like this:

import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  overwrite: true,
  schema: 'src/lib/schema.graphql',
  documents: 'src/**/*.ts',
  generates: {
    'src/lib/gql/': {
      preset: 'client',
      plugins: [],
      config: {
        useTypeImports: true // The updated setting.
      }
    }
  }
}

export default config

It fixed the problem with Vite.

Vite is having issues importing @graphql-typed-document-node/core as a value, it worked with v3.1.1 because there we had an empty file that we used for value imports - but this changes. Am looking into ways of handling this.

A proper approach would also be to use type imports for type-only modules, I made a PR here: https://github.com/joulev/debug/pull/1.

I’m hitting the same problem when building an app with vite:

Error: [commonjs--resolver] Failed to resolve entry for package "@graphql-typed-document-node/core". The package may have incorrect main/module/exports specified in its package.json.

I already had useTypeImports: true in my codegen config, so that doesn’t fix it.

Removing "verbatimModuleSyntax": true from my tsconfig file does fix it (regardless of whether useTypeImports is true or false).

Adding the optimizeDeps value to my vite config didn’t do any good.

I also tried installing @graphql-typed-document-node/core v3.1.1, but it seems like for this to be compatible with GraphQL Code Generator I’d also have to revert to a significantly older version of their client preset (and possibly other packages).


Summing up: removing "verbatimModuleSyntax": true from my tsconfig is the only thing that has fixed the build error so far.

@enisdenjo Echoing @mogelbrod: would it be possible to readd the empty JS file until some other solution is found?

Thank you, it worked. (Don’t worry about the deployment failure; it was because I didn’t configure Vercel to build SvelteKit in that repo.)

Since I intend to keep the debug repo as-is so future people can come to this issue and see the reproduction repo as when it was reported, I think I will close your PR and commit to the main repo instead (see above).

@enisdenjo Thanks for the reply. I retried just now with all node_modules removed and reinstalled, but the same thing happened.

My repo is a SvelteKit Vite app, where this package is used as part of GraphQL codegen; it’s available here if you want a repro repo right now, but since it’s a monorepo I will create a repro repo as minimal as possible instead, and will get back to you in a few hours.