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

Error "The package may have incorrect main/module/exports specified in its package.json." #152

Open
joulev opened this issue Feb 26, 2023 · 18 comments
Assignees

Comments

@joulev
Copy link

joulev commented Feb 26, 2023

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:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ca21228b.js:22005:11)
    at resolvePackageEntry (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ca21228b.js:22002:5)
    at tryNodeResolve (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ca21228b.js:21737:20)
    at Object.resolveId (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ca21228b.js:21488:28)
    at Object.handler (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ca21228b.js:44872:19)
    at file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24163:40
    at async PluginDriver.hookFirstAndGetPlugin (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24063:28)
    at async resolveId (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:23007:26)
    at async ModuleLoader.resolveId (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:23271:15)
    at async Object.resolveId (file:https:///Users/joulev/dev/www/webapps/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ca21228b.js:7972:10)
@dotansimha
Copy link
Owner

This package is type-only package, and does not include any code.
@n1ru4l any idea if we should adjust the config in bob?

@n1ru4l
Copy link
Collaborator

n1ru4l commented Feb 27, 2023

@dotansimha Should be supported by bob. 🤔 https://github.com/kamilkisiela/bob/pull/144/files#diff-691ec73579d989528bc5e4a7db013c029b3c478b3360d962ad5548a0ce42d1c1

I'll have a look.

@enisdenjo enisdenjo self-assigned this Feb 27, 2023
@enisdenjo
Copy link
Collaborator

Hey @joulev, thanks for reporting this!

However, I have not been able to replicate this - I'll keep trying but in the meantime; have you tried a clean install (remove node_modules recursively and run install again)? Maybe share more info like the package.json, or ideally a repro?

@joulev
Copy link
Author

joulev commented Feb 27, 2023

@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.

@enisdenjo
Copy link
Collaborator

Thank you very much! That will help out definitely. In the meantime, I will try out a few things. 👍

@joulev
Copy link
Author

joulev commented Feb 27, 2023

@enisdenjo Reproduction repo

Sorry as it might not be as minimal as you expected it to be, but I am not confident enough to make it any more minimal.

For the repo, if you run pnpm install and pnpm build it will fail. Changing the version of @graphql-typed-document-node/core to v3.1.1 fixes the build error.

@enisdenjo
Copy link
Collaborator

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: joulev/debug#1.

@joulev
Copy link
Author

joulev commented Feb 27, 2023

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).

@websitevirtuoso
Copy link

The plugin "vite:dep-scan" was triggered by this import

script:/home/viktord/Projects/renthome/dashboard/src/modules/notifications/modules/NotificationsBtnDeleteAll.vue?id=0:26:7:
  26 │ import '@graphql-typed-document-node/core'
     ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I started to get this error as well. I have no idea what happened but it worked many month and stopped

@websitevirtuoso
Copy link

you can try adding an exclusion rule for the @graphql-typed-document-node/core package in your Vite configuration. vite.config.js

It will help till this package will be fixed or vite will be fixed

export default {
  // ...other config options

  optimizeDeps: {
    exclude: ['@graphql-typed-document-node/core'],
  },
};

@emj365
Copy link

emj365 commented Jun 12, 2023

For pnpm:

pnpm i graphql @graphql-typed-document-node/core
pnpm i -D typescript ts-node @graphql-codegen/cli @graphql-codegen/client-preset

https://the-guild.dev/graphql/codegen/docs/guides/react-vue#installation

@rbozan
Copy link

rbozan commented Aug 17, 2023

I have the same also using Sveltekit + Vite. Both #152 (comment) and #152 (comment) do not work. It does seem that #152 (comment) works though.

@romelperez
Copy link

romelperez commented Aug 21, 2023

Using @graphql-codegen/[email protected], 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.

@mogelbrod
Copy link

[email protected] + [email protected] configured with tsconfig.json

{
  "compilerOptions": {
    "module": "ESNext",
    "verbatimModuleSyntax": true,
  }
}

Refuses to build with this 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.

Enabling useTypeImports unfortunately doesn't work for me.
I also unsuccessfully tried adding the following to vite.config.ts:

export default defineConfig({
  // ...
  optimizeDeps: {
    exclude: ['@graphql-typed-document-node/core'],
  },
}

Would it be possible to perhaps re-add the empty JS main file back into the repository?
verbatimModuleSyntax is necessary to make typescript annotate type-only imports with type.

@snmabaur
Copy link

snmabaur commented Mar 6, 2024

Same problem here with Vite v5.1.5 / Vue3

export default defineConfig({
  // ...
  optimizeDeps: {
    exclude: ['@graphql-typed-document-node/core'],
  },
}

Doesn't work for me either

{
  "compilerOptions": {
    "module": "ESNext",
    "verbatimModuleSyntax": true,
  }
}

Also that fix doesn't work for my setup

@mmirus
Copy link

mmirus commented Mar 20, 2024

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?

@snmabaur
Copy link

snmabaur commented Apr 5, 2024

I have the same problem here with Vite 5.2.8 and Vue3

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.

@vimutti77
Copy link

For pnpm:

pnpm i graphql @graphql-typed-document-node/core
pnpm i -D typescript ts-node @graphql-codegen/cli @graphql-codegen/client-preset

https://the-guild.dev/graphql/codegen/docs/guides/react-vue#installation

After I migrate from npm to pnpm, the types are broken.
This solution is worked for me. Thanks!

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

No branches or pull requests