lucasfeliciano / fetch-everywhere

WHATWG Fetch API, for ALL JavaScript environments!
MIT License
52 stars 13 forks source link

self is not defined #2

Closed montogeek closed 8 years ago

montogeek commented 8 years ago

Hi!

I am transpiling my library with Rollup, this is the compiled file:

var fetchNpmBrowserify = __commonjs(function (module, exports, global) {
// the whatwg-fetch polyfill installs the fetch() function
// on the global object (window or self)
//
// Return that as the export for use in Webpack, Browserify etc.

var globalObj = self || __commonjs_global.self || __commonjs_global;
module.exports = globalObj.fetch.bind(globalObj);
});

Then, another project that uses my library is running its tests in a Node environment, getting the self is not defined error:

var globalObj = self || __commonjs_global.self || __commonjs_global;
                ^

ReferenceError: self is not defined
jtuchsen commented 8 years ago

I ran into this issue with React Native as well. I've submitted a pull request to fix the issue by adding a typeof check around the self variable.

lucasfeliciano commented 8 years ago

This should be fixed with #3 :)

Let me know if this error persists