Graphql-code-generator: Duplicate declaration "Component"

Created on 11 Jan 2019  路  8Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
When ever I run webpack it gives me Duplicate declaration "Component" in the generated-models.tsx file

To Reproduce
Steps to reproduce the behavior:

  1. Any generated-models.tsx
  2. Run with webpack & babel typescript preset
  3. Run the following command: gql-gen ...

Expected behavior
Would be not to have generated-models.tsx: Duplicate declaration "Component"

Environment:

  • OS: Mac OS Sierra
  • Codegen: 0.15.2
  • Node: v8.12.0

UPDATE: I also tried ts-loader instead of babel-loader & it gave me

TS2345: Argument of type '{ new (): Document; prototype: Document; }' is not assignable to parameter of type 'DocumentNode'.
  Type '{ new (): Document; prototype: Document; }' is missing the following properties from type 'DocumentNode': kind, definitions

UPDATE: I got ts-loader to work & compile with another generate. Babel typescript preset doesn't support namespaces so I think that's why it doesn't work.

Most helpful comment

@dragonfire1119 im running into the same issue...

Duplicate declaration "Document"

How did you get around this? do you mind providing more details?

All 8 comments

@dragonfire1119 im running into the same issue...

Duplicate declaration "Document"

How did you get around this? do you mind providing more details?

@harrisrobin Have you tried ts-loader with webpack? I've moved on from this awhile ago. I seem to remember it was Babel typescript problem. I went through some headaches on getting it right but it's working perfect now.

@dragonfire1119 gave up on CRA's typescript support because they don't support namespacing and reverted back to using tsc. It's a shame they don't support namespacing though! really a blocker for me because this tool is more useful than dropping tsc.

@harrisrobin You can use noNamepsaces configuration and the output will work with CRA (see https://graphql-code-generator.com/docs/integrations/create-react-app)

@harrisrobin I'm also getting Duplicate declaration "Document"

Is there anyway to solve this without turning off namespaces? I'm using next.js and babel to transpile my typescript

@seawatts Babel has said they are not going to support namespaces already https://github.com/babel/babel/issues/8244

@seawatts Babel's TypeScript support has a lot of issues like that. I recommend you to use TypeScript's own compiler which already handles JSX transpilation, and you can make a bundle with Webpack.

In the recent refactor, we removed namespaces completely, so now everyone should be able to use it without loosing the ability to use other features.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edorivai picture edorivai  路  3Comments

jackhkmatthews picture jackhkmatthews  路  3Comments

NickClark picture NickClark  路  3Comments

NickClark picture NickClark  路  3Comments

fvisticot picture fvisticot  路  3Comments