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 loading preset when transpiling TS->ESM #8358

Open
mikaelkaron opened this issue Sep 13, 2022 · 1 comment
Open

error loading preset when transpiling TS->ESM #8358

mikaelkaron opened this issue Sep 13, 2022 · 1 comment
Assignees
Labels
core Related to codegen core/cli

Comments

@mikaelkaron
Copy link

mikaelkaron commented Sep 13, 2022

Describe the bug

In relation to 32c1560 where the err.code was ERR_MODULE_NOT_FOUND in esm instead of MODULE_NOT_FOUND - if transpiling via ts-node and esm err.code is undefined. I'm guessing it's because ts-node generates it's own errors that don't have the err.code set.

There's an upstream issue in ts-node about this, but a temporary fix is to add err.code !== undefined here

Your Example Website or App

...

Steps to Reproduce the Bug or Issue

  1. create config using @graphql-codegen/near-operation-file
  2. configure typescript to use ESM
  3. load schema from .ts file via ts-node using NODE_OPTIONS='--loader ts-node/esm' graphql-codegen-esm

Expected behavior

@graphql-codegen/near-operation-file to be loaded

Screenshots or Videos

No response

Platform

  • OS: Linux
  • NodeJS: 18.8.0
  • graphql version: 16.6.0
  • @graphql-codegen/* version(s):
"@graphql-codegen/add": "^3.2.1",
"@graphql-codegen/cli": "^2.12.0",
"@graphql-codegen/near-operation-file-preset": "^2.4.1",
"@graphql-codegen/typed-document-node": "^2.3.3",
"@graphql-codegen/typescript": "^2.7.3",
"@graphql-codegen/typescript-operations": "^2.5.3",

Codegen Config File

projects:
  operations:
    schema: ./src/graphql/schema/index.ts
    documents:
      - ./src/components/**/*.graphql
    extensions:
      codegen:
        emitLegacyCommonJSImports: false
        generates:
          ./src/components/:
            preset: near-operation-file
            plugins:
              - add:
                  content:
                    - '// this file was auto generated by graphql-codegen'
              - typescript-operations
              - typed-document-node

Additional context

  • tsconfig.json:
{
  "compilerOptions": {
    "strict": true,
    "declaration": true,
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "ESNext",
    "rootDir": "src",
    "outDir": "dist"
  }
}
@charlypoly charlypoly self-assigned this Sep 20, 2022
@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
@i-tengfei
Copy link

Same issue, any update?

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

No branches or pull requests

3 participants