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.

Invariant Violation: Element type is invalid

See original GitHub issue

Expected behavior

When I test with enzyme using shallow render - I should be able to .find(‘DatePicker’) but it returns 0 results. - trying with mount() throws an error

	Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

and that error is on the mount itself before I even try to find it

Actual behavior

Steps to reprodcue

the components under test

<div className='l-flex l-flex-c t-field t-field-pad'>
                <label>
                    LMP
                </label>
                <i className='t-sep'/>
                <span className='t-validation-wrap l-fg1'>
                     <DatePicker
                         locale={'he-IL'}
                         className='t-field-text w100 t-field--date'
                         selected={this.state.selectedDate ? moment(this.state.selectedDate) : null}
                         onChange={this._setDate}
                     />
                </span>
            </div>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11

github_iconTop GitHub Comments

2reactions
carlostxmcommented, May 25, 2018

Changing import to const DatePicker = require('react-datepicker'); worked for me and I can launch tests using jest + enzyme.

However, with this change the application cannot launch and now I’m getting this error in the console:

React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
1reaction
dwilhel1commented, Apr 15, 2021

Thanks to a coworker pointing this thread out, the expected a string (for built-in components) or a class/function (for composite components) but got: object error we had was resolved with the following:

Old

<DatePicker />

New

<DatePicker.default />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught Error: Invariant Violation: Element type is invalid ...
This error can rise if you try to import a non-existent component. Make sure you have no typo and that the component indeed...
Read more >
Invariant Violation: Element type is invalid: expected a ...
Invariant Violation : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Read more >
(React) Element type is invalid, expected a string (for built ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >
Invariant Violation: Element type is invalid ... - YouTrack
Invariant Violation : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >
Error Invariant Violation Element type is invalid expected a ...
Error Invariant Violation Element type is invalid expected a string for built-in components or a class function but got object.
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