react-dropzone: Element type is invalid error
Do you want to request a feature or report a bug?
- I found a bug
- I want to propose a feature
What is the current behavior?
It seems like the plugin not getting imported following the installation guidance
React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components)
and
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
What I have tried to fix the problem?
I have seen various possible ways to fix it but none of them worked. For example importing like
import { Dropzone } from 'react-dropzone'
instead of
import Dropzone from 'react-dropzone'
But that will not solve the problem. The only way I made it work is by downgrading to version 4.1.3 as someone mentioned before, but thats no use as it has a major bug which crashes the browser as been reported in #549
Please mention other relevant information such as the browser version, Operating System and react-dropzone version.
react-dropzone 4.2.5 Chrome Version 63.0.3239.132 npm 5.6.0 node 6.12.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 31
Commits related to this issue
- Resovled react-dropzone failing in test - https://github.com/react-dropzone/react-dropzone/issues/554#issuecomment-401898536 — committed to StaceC/implib by StaceC 6 years ago
I still have the same problem. But importing like this works:
import * as Dropzone from 'react-dropzone';worked for me
@yebrahim I’m using
react-scripts-tsandimport Dropzone from 'react-dropzone';works without any issues (make sure you have theallowSyntheticDefaultImportsflag enabled intsconfig.json).Typings are now baked in this package, in case you use the ones from
@types.I digged a bit deeper, for me the problem was that I used ts-jest without
"allowSyntheticDefaultImports": true,in the tsconfig.json - that doesn’t seem to work with react-dropzone. TL;DR: Add `“allowSyntheticDefaultImports”: true to the tsconfig when using ts-jest 😃For some reason, this worked with the normal webpack build, but not when using jest:
public render() { return <div> <Dropzone> Click here or drop ableton projects </Dropzone> </div>; }was compiled to:
this.__proto__.render.toString() "render() { return React.createElement("div", null, React.createElement(react_dropzone_1.default, null, "Click here or drop ableton projects")); { } }"the extra [default] breaks it in this case, as this is undefined. I’ll check my build config once more, but if someone stumbles over this issue it might be helpful.
Same issue for me. I can fix it by adding
"allowSyntheticDefaultImports": truebut then that breaks other things in my app.So for now this is my fix:
@SourceCipher @kildem @okonet I fixed this issue by disabling module transformation by the Babel. I.e. in
.babelrc:I have the same
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.problem. and I usejs import Dropzone from "react-dropzone";This problem occurs immediately after I started using code splitting with Webpack. It affected a few other libraries such as
redux-sagaas well.as @mojadev said, using <Dropzone.default /> solves it (same thing with
redux-saga)only this workaround worked for me. Im using ts-jest. I had “Element type is invalid: expected a string (for built-in components)” problem
+1. If you’re, like me, using create-react-app with Typescript, there’s no way I can find around this problem. I can’t even try any of the solutions above. 😦
After trying several described methods, I ended up using:
@gtwilliams03 No, it isn’t a good fix form me. I have client and server rendering. As temp fix I build a local implementation of drag and drop
I have the same as @mojadev said, using <Dropzone.default /> solved the problem, but only on client side, on server rendering it throw error:
Warning: React.createElement: 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.