The problem is that typeof __dirname !== 'undefined' condition is compiled to true with webpack bundle loader. A good check could be typeof module !== 'undefined' && module.exports which also underscore.js is using. This is not possible though because transpiled code in dist/index.js defines the following code, defining module.exports:
Another issue solved here is that the require('whatwg-fetch') doesn't export the fetch function, but it defines it on the global scope, so we have to assign fetchUrl = fetch; just like the native browser function.
Finally, tests pass, so let me know if you are ok with this PR. :)
Note: Chrome and Firefox have native browser implementation for fetch.
According to the issue https://github.com/kadirahq/lokka-transport-http/issues/13 fetch loading is not possible on Safari.
The problem is that
typeof __dirname !== 'undefined'
condition is compiled totrue
with webpack bundle loader. A good check could betypeof module !== 'undefined' && module.exports
which also underscore.js is using. This is not possible though because transpiled code indist/index.js
defines the following code, definingmodule.exports
:So the solution on checking the current environment can be this check
var isNode=new Function("try {return this===global;}catch(e){return false;}");
better explained here http://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser.Another issue solved here is that the
require('whatwg-fetch')
doesn't export the fetch function, but it defines it on the global scope, so we have to assignfetchUrl = fetch;
just like the native browser function.Finally, tests pass, so let me know if you are ok with this PR. :)
Note: Chrome and Firefox have native browser implementation for fetch.