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

Support .mts extension for codegen file / package.json "type": "module" #8862

Closed
n1ru4l opened this issue Jan 30, 2023 · 5 comments · Fixed by #9086
Closed

Support .mts extension for codegen file / package.json "type": "module" #8862

n1ru4l opened this issue Jan 30, 2023 · 5 comments · Fixed by #9086
Assignees

Comments

@n1ru4l
Copy link
Collaborator

n1ru4l commented Jan 30, 2023

Is your feature request related to a problem? Please describe.

It is currently impossible to have a codegen.mts config.

Describe the solution you'd like

Support the .mts extension.

Describe alternatives you've considered

Use import() instead of require() in order to properly support importing all kinds of modules.

Is your feature request related to a problem? Please describe.

No response

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Jan 30, 2023

See cosmiconfig/cosmiconfig#224

@n1ru4l n1ru4l changed the title Support .mts extension for codegen file Support .mts extension for codegen file / package.json "type": "module" Jan 30, 2023
@mirismaili
Copy link

mirismaili commented Feb 9, 2023

AFAIK when "type": "module" we don't need .mjs/.mts extension.


My problem is I have "type": "module" in my "package.json" file. And I get this error:

> graphql-codegen --config codegen.ts

TypeScriptLoader failed to compile TypeScript:
Must use import to load ES Module: codegen.ts
require() of ES modules is not supported.
require() of codegen.ts from node_modules/cosmiconfig-typescript-loader/dist/cjs/index.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from package.json.

So I was forced to use yaml config format.

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Feb 9, 2023

@mirismaili Yes, this is an upstream dependency issue.

@xiaoxinghu
Copy link

Having exactly the same issue.

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Feb 16, 2023

@xiaoxinghu For now the following workaround is recommended:

#8509 (comment)

for those running into this issue where a static YAML file is not a solution, you can rename your file to codegen.cjs

/** @type {import('@graphql-codegen/cli').CodegenConfig} */
const config = {
  // ...
}

module.exports = config

and then modify your scripts in package.json accordingly

"scripts": {
  "codegen": "graphql-codegen --config codegen.cjs",
}

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