apollo-tooling icon indicating copy to clipboard operation
apollo-tooling copied to clipboard

code generator should not generate empty global-types

Open macrozone opened this issue 5 years ago • 9 comments

continuation of https://github.com/apollographql/apollo-tooling/issues/1179#issuecomment-616496523

Intended outcome:

global-types.ts cannot be empty as this breaks typescript compiler when --isolatedModules is set. This option can not be disabled for nextjs users

Actual outcome:

if there is nothing to put into global-types.ts, apollo generates an empty file. This throws an error on build Type error: All files must be modules when the '--isolatedModules' flag is provided.

How to reproduce the issue:

set isolatedModules and run a build

Versions

apollo 2.28.3

macrozone avatar Aug 17 '20 19:08 macrozone

a workaround to that would be to just exclude it in tsconfig.json "exclude": ["./src/__generated__/globalTypes.ts"]

langarus avatar Sep 30 '20 12:09 langarus

I also had the same problem. Seems like the only way for now is to exclude globalTypes in tsconfig.json

alitourani avatar Oct 10 '20 05:10 alitourani

This is also a problem in Create React App.

Excluding the file is not a great workaround, as the exclusion must be removed once there are contents in the file.

CRA suggests adding export {} to trick the compiler into treating it as a module. That seems like a pretty bad hack. I agree that it would be better not to write the file when it's empty.

paulmelnikow avatar Nov 13 '20 17:11 paulmelnikow

I opened #2163 to fix this.

paulmelnikow avatar Nov 13 '20 18:11 paulmelnikow

really guys, can we PLEASE get this fixed? This is a complete unnecessary problem thats wasting everybody's time.

macrozone avatar Mar 04 '22 15:03 macrozone

@hwillson anyone, please, we beg you. We know it has no longer priority for you, but its really small problem to fix and would help so many people.

macrozone avatar Mar 04 '22 15:03 macrozone

@macrozone I'll take a look!

hwillson avatar Mar 04 '22 18:03 hwillson

@macrozone I'll take a look!

thank you, sorry for bragging. 😳

see also https://github.com/apollographql/apollo-tooling/pull/2163

macrozone avatar Mar 05 '22 09:03 macrozone

Whoa, blast from the past! I ran into this issue again today, and realized #2163 hasn't been merged. @hwillson I just updated the PR and the tests are passing now. Could I ask you to please take a look?

paulmelnikow avatar Mar 17 '22 19:03 paulmelnikow