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

Provide a default export for typescript codegen files to work nicely with webpack --isolatedModules flag #2030

Open
mikeldking opened this issue Jul 5, 2020 · 1 comment

Comments

@mikeldking
Copy link

When using the --isolatedModules webpack flag, each file must have at least one import/export. This flag is set by default when using frameworks such as next.js. Typescript codegen can produce empty type files, causing the build to break for projects that use this flag.

yarn run v1.15.2
$ next build
Creating an optimized production build

Failed to compile.

/project/src/types/gqlTypes.ts
ERROR in /project/src/types/gqlTypes.ts(1,1):
1:1 All files must be modules when the '--isolatedModules' flag is provided.
  > 1 | /* tslint:disable */
      | ^
    2 | /* eslint-disable */
    3 | // @generated
    4 | // This file was automatically generated and should not be edited.

Currently I need to manually put the following at the end of each file.

export default {};

Would it be possible to do this as part of codegen?

P.S. Here is a stackoverflow thread about this issue: https://stackoverflow.com/questions/56577201/why-is-isolatedmodules-error-fixed-by-any-import/56577324

@ryan-rushton
Copy link

I got around this issue with the setting --globalTypesFile src/__generated-globals__/globalTypes.d.ts. This means you won't need to manually add that line each time you generate your client.

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

2 participants