apollographql / apollographql/apollo-tooling

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

Open
#2,030 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

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.

```bash
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.
```typescript
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

Contributor guide

Open the contributing guide

Research direction

Start with the generated src/types/gqlTypes.ts example and trace the TypeScript codegen path that produces empty type files. Verify the change by generating an empty type file and confirming it builds with webpack or Next.js using --isolatedModules without the manual export.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.