Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: FileUploadWithPreview is not a constructor #19

Closed
GrzegorzWalewski opened this issue Mar 14, 2019 · 5 comments
Closed

TypeError: FileUploadWithPreview is not a constructor #19

GrzegorzWalewski opened this issue Mar 14, 2019 · 5 comments

Comments

@GrzegorzWalewski
Copy link

I had this script on my site, and now it stop working...
Error i have is "TypeError: FileUploadWithPreview is not a constructor"
Can You help it?

@deniseileen
Copy link
Contributor

deniseileen commented Mar 14, 2019

Because of some recent changes that we’re working through, you’re going to want to make sure you’re including the library at a certain version. To anyone coming to this issue with a new TypeError: FileUploadWithPreview is not a constructor error, you should update your javascript library script import to <script src="https://unpkg.com/file-upload-with-preview@3.1.3/dist/file-upload-with-preview.min.js"></script>. See below for another way to fix the issue, but may leave you with an error in the future. It’s pretty universally recommended to specify versions in dependencies for safety reasons.

Initial answer:

Hey, sorry about that - we made some changes today that affect the usage. You can either update your code to use .default on the initialization: var upload = new FileUploadWithPreview.default('myUniqueUploadId'), or you can specify an older version - changing to 3.1.3 should solve the issue for you.

@GrzegorzWalewski
Copy link
Author

Thanks, it works 😄

@johndatserakis
Copy link
Owner

johndatserakis commented Mar 19, 2019

Hey Grzegorz - we just pushed a fix to the default issue. If you have not hardcoded the version number in you importing of this library, then you may run into an issue with this latest push.

If you do run into an issue now, please use the following import code to lock in your version:

<script src="https://unpkg.com/file-upload-with-preview@3.2.8/dist/file-upload-with-preview.min.js"></script>

Also, you can remove the default from your initialization. So it should look like this:

var upload = new FileUploadWithPreview('myUniqueUploadId')

Sorry for the trouble and for you having to update your code. Please let us know if we can assist further. Thank you.

@rogerarruda
Copy link

Hello, I'm having the same problem importing from NPM into a JS file.

File plugins.js using webpack:

window.FileUploadWithPreview = require('file-upload-with-preview');

When I see in the browser, the error appears:

Uncaught TypeError: FileUploadWithPreview is not a constructor

My script into HTML

<script type="application/javascript">
        const upload = new FileUploadWithPreview('uploadImage', { text: {chooseFile: 'Selecione um arquivo', browse: 'Selecionar'} });
</script>

@wikichua
Copy link

wikichua commented Aug 6, 2020

on app.js
const FileUploadWithPreview = window.FileUploadWithPreview = require('file-upload-with-preview/src/file-upload-with-preview').default;

@johndatserakis johndatserakis unpinned this issue Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants