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:
yarn add apollo-boost graphql react-apollo@betaVersion
Incidentally, I cannot run the typescript example in this repo, either.
I am having the same issue. As soon as
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
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/*.mjsor
“postinstall”: “rm -f node_modules/react-apollo/*.mjs ../../node_modules/react-apollo/*.mjs”(if you're using yarn modules)