React-apollo: Typescript + react-apollo beta + webpack fails / Typescript example does not run

Created on 2 Mar 2018  ·  11Comments  ·  Source: apollographql/react-apollo

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

Most helpful comment

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)

All 11 comments

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

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).

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

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)

It's broken in create-react-app-typescript also: https://github.com/wmonk/create-react-app-typescript/issues/259

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.

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!

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

@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.

Closing - housekeeping

Was this page helpful?
0 / 5 - 0 ratings