fortana-co / react-dropzone-uploader

React file dropzone and uploader
https://react-dropzone-uploader.js.org/
MIT License
446 stars 183 forks source link

Seems not to work with create-react-app #20

Open cgraupner-bm opened 5 years ago

cgraupner-bm commented 5 years ago

If I try to use the library inside a create-react-app project, I get compilation error:

Failed to compile.

./node_modules/react-dropzone-uploader/dist/Dropzone.tsx 18:7
Module parse failed: Unexpected token (18:7)
You may need an appropriate loader to handle this file type.
| } from './utils'
| 
> export type StatusValue =
|   | 'rejected_file_type'
|   | 'rejected_max_files'

Steps to reproduce:

  1. Create react-app project

    yarn create react-app my-dropzone-app --typescript
  2. install react-dropzone-uploader

    cd my-dropzone-app
    yarn add react-dropzone-uploader
  3. Modify src/App.tsx to include dropzone. (It's the Standard example from your examples in Typescript) Edit the src/app.tsx and include the following code before const App: [...]

    
    import Dropzone, {
    IDropzoneProps
    } from "react-dropzone-uploader/dist/Dropzone"

const Standard = () => { const getUploadParams: IDropzoneProps['getUploadParams'] = () => { return { url: 'https://httpbin.org/post' } }

const handleChangeStatus: IDropzoneProps['onChangeStatus'] = ({ meta }, status) => { console.log(status, meta) }

const handleSubmit: IDropzoneProps['onSubmit'] = (files, allFiles) => { console.log(files.map(f => f.meta)) allFiles.forEach(f => f.remove()) }

return ( <Dropzone getUploadParams={getUploadParams} onChangeStatus={handleChangeStatus} onSubmit={handleSubmit} styles={{ dropzone: { minHeight: 200, maxHeight: 250 } }} /> ) }



4. Add `<Standard/>` before the last `</div>` in the return of the `App` function component.
5. Start the dev server with `yarn start`
6. You should see now the compilation error.
g-bar commented 5 years ago

Hi @cgraupner-bm

Thanks for reporting this issue. Try importing from react-dropzone-uploader (instead of "react-dropzone-uploader/dist/Dropzone")like this:

import Dropzone, {
  IDropzoneProps
} from "react-dropzone-uploader"

it works and you still get typescript type checking.

Let me know if that solves it.