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

graphql-codegen-esm throws loadTs is not a function #8212

Closed
mikaelkaron opened this issue Aug 10, 2022 · 6 comments · Fixed by #8289
Closed

graphql-codegen-esm throws loadTs is not a function #8212

mikaelkaron opened this issue Aug 10, 2022 · 6 comments · Fixed by #8289
Assignees

Comments

@mikaelkaron
Copy link

Describe the bug

When trying the official esm example loadTs is not a function is thrown

Your Example Website or App

https://github.com/dotansimha/graphql-code-generator/tree/master/examples/typescript-esm

Steps to Reproduce the Bug or Issue

  1. fetch local copy of https://github.com/dotansimha/graphql-code-generator/tree/master/examples/typescript-esm
  2. run npm run codegen

Expected behavior

Expected the example to work

Screenshots or Videos

No response

Platform

  • OS: Windows
  • NodeJS: 18.4
  • graphql version: 16.5
  • @graphql-codegen/* version(s): as example

Codegen Config File

No response

Additional context

No response

@mikaelkaron
Copy link
Author

Playing around a bit this looks to be an upstream problem in graphql-config and how it loads cosmiconfig-typescript-loader (well, the actual problem is probably in how cosmiconfig-typescript-loader generates types)

In the generated index.mjs file you can "fix" the problem like this:

import loadTsx from 'cosmiconfig-typescript-loader';
...
const loadTs = loadTsx.default

So it looks like the correct default export is not correctly picked up between CJS and ESM. I've seen this in a few projects since I started transitioning to ESM and the default-import package can help to bridge this problem.

@mikaelkaron
Copy link
Author

there's a relevant coment in the TypeScript repo for reference.

@lednhatkhanh
Copy link

I'm also facing the same problem.

@n1ru4l
Copy link
Collaborator

n1ru4l commented Aug 26, 2022

@mikaelkaron What index.mjs file are you referring to?

@mikaelkaron
Copy link
Author

mikaelkaron commented Aug 26, 2022

The index.mjs discussed is generated from https://github.com/kamilkisiela/graphql-config/blob/master/src/helpers/cosmiconfig.ts#L2, so the fix will have to be applied in that package.

I see now linking to it that there is a fix landed in their master branch, so perhaps a new version is on its way.

Edit: I now also realized that it’s you fixing the file :)

@n1ru4l
Copy link
Collaborator

n1ru4l commented Aug 26, 2022

@mikaelkaron New release with this fix is on the way :) https://github.com/dotansimha/graphql-code-generator/releases

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 a pull request may close this issue.

4 participants