Skip to content

Fix import from Node environment (to not break in server side rendering) #86

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

Merged
merged 2 commits into from
Jul 13, 2017

Conversation

gre
Copy link
Contributor

@gre gre commented Jul 13, 2017

the library is breaking in Node environment with a window is not defined – not at runtime, but at import time. that PR fixes this.

my only usecase is to have the library working with Server Side Rendering (in context of react). (in my case, the library don't actually gets used in Node, but it's still imported and embedded in the server bundle that will break before this PR)

@blueimp
Copy link
Owner

blueimp commented Jul 13, 2017

Thanks for your contribution, @gre !

I've just two change requests:

In js/load-image.js, could you change the urlAPI declaration to the following

  var urlAPI = ($.createObjectURL && $) ||
                ($.URL && URL.revokeObjectURL && URL) ||
                ($.webkitURL && webkitURL)

and in the same file, change window.FileReader to $.FileReader for consistency.

@blueimp
Copy link
Owner

blueimp commented Jul 13, 2017

And please make sure the code passes npm test :)

@gre
Copy link
Contributor Author

gre commented Jul 13, 2017

fixed and test pass

@blueimp blueimp merged commit 5f93152 into blueimp:master Jul 13, 2017
@ram-you
Copy link

ram-you commented Jul 14, 2017

The new "2.13.0" breaks my project.
With "2.12.2" this works :

import loadImage from 'blueimp-load-image/js'
window.loadImage = loadImage

With the new version it doesn't work anymore.

@gre
Copy link
Contributor Author

gre commented Jul 14, 2017

oops i'm not 100% sure but, I think reason is that (this) does not yield window in context of Browserify/Babel , but not sure?

@blueimp maybe we should drop the scopping thing and just typeof everywhere? in load-image.js ?

if it's not the reason, then it must be another issue?

@gre
Copy link
Contributor Author

gre commented Jul 14, 2017

@ram-you have you tried to use import loadImage from 'blueimp-load-image' without the /js ? it seems to work for me mmh

@ram-you
Copy link

ram-you commented Jul 14, 2017

@gre

import loadImage from 'blueimp-load-image'

Sorry, but your solution doesn't work for me.

@blueimp
Copy link
Owner

blueimp commented Jul 15, 2017

@ram-you I've just released version 2.13.1 which should fix the issue.

@ram-you
Copy link

ram-you commented Jul 15, 2017

Thank you @blueimp . It's works like a charm

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

Successfully merging this pull request may close these issues.

3 participants