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

StenciljsError: ReferenceError: File is not defined #92

Closed
Scan0815 opened this issue Jan 6, 2021 · 5 comments
Closed

StenciljsError: ReferenceError: File is not defined #92

Scan0815 opened this issue Jan 6, 2021 · 5 comments

Comments

@Scan0815
Copy link

Scan0815 commented Jan 6, 2021

hi, i have a problem with my test suite and the browser-image-compression lib.

ReferenceError: File is not defined,
also not working in ssr, get the same error.

i read that you will fix it in 1.0.8, but now i on 1.0.14 and is not working.

You write from a trycatch workaound, but the error will get direct on import call.
import imageCompression from 'browser-image-compression';

error

@Donaldcwl
Copy link
Owner

@Scan0815 Do your test environment has the window object defined? The library detects browser environments by checking the existence of the window object through typeof window !== 'undefined'.

@Scan0815
Copy link
Author

Scan0815 commented Jan 6, 2021

@Donaldcwl hi, thanks for answer.
Yes that´s right, StencilJS has on the test env and on SSR a own window object only with some functions and without File.
i remove for testing your lib and than everything work fin.

I think React prerender, use also a internal window object, hydrating components is not possible without.

Maybe you can check if File exists in window.

@Donaldcwl
Copy link
Owner

@Scan0815 Thanks for your suggestion, extra checking on whether File and FileReader exist in the Window object will be added in the next release.

Donaldcwl added a commit that referenced this issue Jan 7, 2021
…ng on whether File and FileReader exist in the Window object[#92](#92)
@Scan0815
Copy link
Author

@Donaldcwl i have debug a little deeper. I found that not the isBrowser check is the problem.
CustomFile=isBrowser&(moduleMapper&&moduleMapper.getOriginalSymbol(window,"File")||window.File),CustomFileReader=isBrowser&&(moduleMapper&&moduleMapper.getOriginalSymbol(window,"FileReader")||window.FileReader)
i change the two "or" from File | ReadFile to window.File | window.FileReader and now it work.

i hope this help.

@Donaldcwl Donaldcwl mentioned this issue Aug 11, 2021
@Donaldcwl
Copy link
Owner

fixed in v1.0.15

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

2 participants