question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "React.createElement: type is invalid" error with 8.28.5

See original GitHub issue

Dependabot bumped react-intersection-observer in one of my repos to version 8.28.5 and since then, every time I use the <InView triggerOnce> component, I’m getting a following error:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check your code at xxx.js:100.
    in xxx
    in Context.Provider
    in ConnectFunction
    in ConnectFunction (at _app.js:36)
    in App
    in Context.Provider
    in Provider
    in withRedux(App)
    in Unknown
    in Context.Provider
    in Context.Provider
    in Context.Provider
    in Context.Provider
    in AppContainer
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
    at ReactDOMServerRenderer.render (/xxx/node_modules/react-dom/cjs/react-dom-server.node.development.js:3743:17)
    at ReactDOMServerRenderer.read (/xxx/node_modules/react-dom/cjs/react-dom-server.node.development.js:3373:29)
    at renderToString (/xxx/node_modules/react-dom/cjs/react-dom-server.node.development.js:3988:27)
    at Object.renderPage (/xxx/node_modules/next/dist/next-server/server/render.js:48:686)
    at Function.getInitialProps (webpack-internal:///./node_modules/next/dist/pages/_document.js:129:19)
    at Function.getInitialProps (webpack-internal:///./pages/_document.js:20:85)
    at loadGetInitialProps (/xxx/node_modules/next/dist/next-server/lib/utils.js:5:101)
    at renderToHTML (/xxx/node_modules/next/dist/next-server/server/render.js:48:977)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Has anything changed recently with regards to <InView triggerOnce>? Reverting back to 8.27.1 (which was the version previously used in my repo) fixes the problem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
klapeccommented, Sep 24, 2020

I’ve found the culprit: I had InView imported as a default export, not a named one. I changed: import InView from 'react-intersection-observer'; to import { InView } from 'react-intersection-observer'; and it worked. Weird because it worked @ 8.27.1.

0reactions
thebuildercommented, Sep 4, 2021

Can you clarify/make an example?

The package exports all of these, so not sure what problem you might be seeing:

export { InView } from './InView';
export { useInView } from './useInView';
export { observe } from './observe';

export default InView;
Read more comments on GitHub >

github_iconTop Results From Across the Web

React.createElement: type is invalid -- expected a string
Error : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >
Warning: React.createElement: type is invalid -- expected a ...
I have uninstalled and reinstalled reac and react-dom, and the problem still persists, try a new project cloning it from a friend, and...
Read more >
React.createElement: type is invalid — expected a string
The error is happening when you are creating a new element – in this case initiantiating your custom component using createElement. The actual ......
Read more >
Error React createElement type is invalid expected a string for ...
I get the following error. React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for ...
Read more >
JSX In Depth - React
Specifying The React Element Type ... The first part of a JSX tag determines the type of the React element. Capitalized types indicate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found