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 generating ESM output #387

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nigelzor
Copy link

@nigelzor nigelzor commented May 17, 2023

re: #372

Setting emitESM=true in the generator's configuration will switch from using require to import calls in the generated code.

I haven't been successful in actually using the ESM output. Bi-directional relationships between models lead to circular dependencies in *WhereInput and *ListRelationFilter and cause the following error at start-up:

ReferenceError: Cannot access 'FooWhereInput' before initialization
at file:///app/node_modules/@generated/type-graphql/resolvers/inputs/FooListRelationFilter.js:10:31

Even without setting emitESM=true, changing imports to use filenames with extension makes Typescript with moduleResolution=node16 stop complaining about missing types.

@MichalLytek MichalLytek self-requested a review May 18, 2023 18:08
@MichalLytek MichalLytek added enhancement New feature or request community Something initiated by the community labels May 18, 2023
Copy link
Owner

@MichalLytek MichalLytek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of regression. *.js import should be emitted only for esm.

@nigelzor nigelzor force-pushed the emit-esm branch 2 times, most recently from 4366ba7 to ef99728 Compare May 18, 2023 18:56
@nigelzor nigelzor closed this May 18, 2023
@nigelzor nigelzor reopened this May 18, 2023
@nigelzor
Copy link
Author

This is how I'd originally written the change, but I didn't like needing to pass options into every import generator. If this is how you'd prefer to see it 👌.

Setting `emitESM=true` in the generator's configuration will switch from
using `require` to `import` calls in the generated code.

I haven't been successful in actually using the ESM output. Bi-directional
relationships between models lead to circular dependencies in
`*WhereInput` and `*ListRelationFilter` and cause the following error at
start-up:

> ReferenceError: Cannot access 'FooWhereInput' before initialization
>     at file:///app/node_modules/@generated/type-graphql/resolvers/inputs/FooListRelationFilter.js:10:31

Regardless of ESM setting, create a package.json if generating into
node_modules. This makes sure that the generated code doesn't inherit a
parent package's `type`.
@woss
Copy link

woss commented May 23, 2024

i second this PR

@vko-online
Copy link

So esm support not happening anytime soon right?

@PS1TD
Copy link

PS1TD commented Oct 21, 2024

+1 Need this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Something initiated by the community enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants