cozy / cozy-client-js

Javascript library to write Cozy applications
https://docs.cozy.io/en/cozy-client-js/README/
MIT License
11 stars 12 forks source link

fix: include isomorphic-fetch in node build #286

Closed doubleface closed 5 years ago

doubleface commented 5 years ago

isomorphic-fetch will allow pouchdb-browser to not cause 'ReferenceError: fetch is not defined' error

y-lohse commented 5 years ago

Do we have some background on this error? Did pouchdb-browser just crash out of the box in node? The plan was that the pouchdb part of the code never runs in node, so fetch shouldn't be required..?

doubleface commented 5 years ago

Do we have some background on this error? Did pouchdb-browser just crash out of the box in node? The plan was that the pouchdb part of the code never runs in node, so fetch shouldn't be required..?

@y-lohse This fetch error appears when the pouchdb-browser package is required, because it is supposed to be used only in the browser and there is no reason for fetch to not be present.

Crash-- commented 5 years ago

@y-lohse Is it what you have in mind : https://github.com/cozy/cozy-client-js/compare/fix/import?expand=1

y-lohse commented 5 years ago

@y-lohse Is it what you have in mind : https://github.com/cozy/cozy-client-js/compare/fix/import?expand=1

I wasn't aware that simply requiring pouchdb would produce an error like that to be honest. But ok, since it does, I think not loading it in a node context is a better long term solution than exposing a fetch function. Not blocking for me though, depends how urgent the fix is.

nono commented 5 years ago

Even without pouchdb, fetch is used in a lot of places in cozy-client-js and isomorphic fetch is listed as a dependency for using cozy-client-js with node:

If you are developing a nodejs app, you will need some polyfills. You can add them to your project with this command: $ yarn add isomorphic-fetch core-js regenerator-runtime btoa

https://github.com/cozy/cozy-client-js/blob/master/docs/intro.md#include-the-library-in-your-application

@doubleface can you update this bit of documentation too?