GeoTIFF / georaster

Wrapper around Georeferenced Rasters like GeoTIFF and soon JPG and PNG that provides a standard interface
Apache License 2.0
84 stars 32 forks source link

ReferenceError: global is not defined when importing the library on client-side #42

Closed aviklai closed 4 years ago

aviklai commented 4 years ago

Description: ReferenceError: global is not defined when importing the library on client-side.

To Reproduce When I try to import the library on a client-side project, I get the above error. It looks like the library is trying to import node-fetch on a client-side environment.

In index.js - the line: import nodeFetch from 'node-fetch'; imports node-fetch in any environment.

Expected behavior The library should work on the client-side as well.

Screenshots image

Desktop:

Maybe it's possible to use isomorphic-fetch or cross-fetch?

DanielJDufour commented 4 years ago

Hi, @aviklai ! Good catch! Happy to work with you on this and share the fix with others :-)

Could you add node-fetch to Webpack's externals and see if that fixes the problem? This is what we did with geoblaze here: https://github.com/GeoTIFF/geoblaze/blob/master/webpack.base.js#L43

I'm not sure that will fix it though. Would you be able to share your webpack config and a little bit of the code that you are using to import the library? Are you using require, import or <script type="module" src="...">? I think the problem might be that I haven't tested this library on mjs builds! We happen to use umd builds for GeoBlaze.

Thank you again and looking forward to fixing this.

aviklai commented 4 years ago

Hi @DanielJDufour ,

I tried adding externals but it didn't fix the problem. I opened a pull request in which I have added a browser build as well. Now, when the library will be imported in a browser environment, it won't pull node-fetch because the build won't contain the node-fetch dependency. On the other hand, in node environment, it will be using node-fetch.

DanielJDufour commented 4 years ago

I merged your PR and republished. Please reopen if you are still having problem

DanielJDufour commented 4 years ago

Thank you!