Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. code example

Example 1: touchableopacity expected a string

This is probably caused by some JS module export/import issues
in your program, typically for one of the two reasons listed below:

- You forget to export, or you export something incorrectly
- You import something that doesn't exist, or you import something incorrectly

Example 2: element type is invalid expected a string

In my case (using Webpack) it was the difference between:

import {MyComponent} from '../components/xyz.js';
vs

import MyComponent from '../components/xyz.js';

Example 3: expected a string (for built-in components) or a class/function (for composite components) but got: undefined

In my case (using Webpack) it was the difference between:

import {MyComponent} from '../components/xyz.js';
vs

import MyComponent from '../components/xyz.js';
The second one works while the first is causing the error. Or the opposite.

Tags:

Misc Example