Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Typescript + react-apollo beta + webpack fails / Typescript example does not run #1750

Closed
joearasin opened this issue Mar 2, 2018 · 11 comments

Comments

@joearasin
Copy link

Intended outcome:

Using the beta react-apollo in a typescript app.

Actual outcome:

Received an "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined"

How to reproduce the issue:

  1. Create a new app with "https://github.com/wmonk/create-react-app-typescript"
  2. Add Apollo dependencies per the Quickstart yarn add apollo-boost graphql react-apollo@beta
  3. Add Apollo provider per documentation
  4. Receive error message

Version

@joearasin
Copy link
Author

Incidentally, I cannot run the typescript example in this repo, either.

@joearasin joearasin changed the title Typescript + react-apollo beta + webpack fails Typescript + react-apollo beta + webpack fails / Typescript example does not run Mar 2, 2018
@jcq
Copy link

jcq commented Mar 4, 2018

I am having the same issue. As soon as is added, this error occurs when using beta 3. Everything works fine when swapping back to beta 2 (though I'd certainly like to use the new components in beta 3).

@joearasin
Copy link
Author

joearasin commented Mar 6, 2018

Poking into this further, this has something to do with the presence of the mjs files -- I'm not sure what is happening, but I'm guessing the typescript compiler is doing something, and webpack is doing something else. Removing the mjs files from the node_modules/react-apollo/lib folder makes things work

@joearasin
Copy link
Author

A post-install hook to clean up the mjs files allowed me to use the RC

Something along the lines of:

“postinstall”: “rm -f node_modules/react-apollo/*.mjs

or
“postinstall”: “rm -f node_modules/react-apollo/*.mjs ../../node_modules/react-apollo/*.mjs”
(if you're using yarn modules)

@mbrowne
Copy link
Contributor

mbrowne commented Mar 6, 2018

It's broken in create-react-app-typescript also: wmonk/create-react-app-typescript#259

@mbrowne
Copy link
Contributor

mbrowne commented Mar 21, 2018

It appears that this is no longer an issue in the latest release candidate. Just tried it with 2.1.0-rc.5 and there are no longer any .mjs files included in the package, so it works fine.

@gaearon
Copy link

gaearon commented Apr 3, 2018

If your project is built with Create React App and not ejected, [email protected] should fix this.
Here is how to upgrade:

https://github.com/facebook/create-react-app/releases/tag/v1.1.2

Otherwise you can apply a similar fix yourself in your project config. Cheers!

@KendoJaaa
Copy link

it doesn't work doing what @gaearon said. but it works when doing like @joearasin said

@mbrowne
Copy link
Contributor

mbrowne commented Apr 11, 2018

@KendoJaaa are you using the official create-react-app, or create-react-app-typescript? Anyway, react-apollo 2.1 has been released now and has fixed this issue, so there's no need to use the beta anymore.

@rosskevin
Copy link
Contributor

Closing - housekeeping

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants