GithubHelp home page GithubHelp logo

Getting referenceerror: self is not defined when running mocha tests in command line as soon as I attempt to use isomorphic-fetch about isomorphic-fetch HOT 15 OPEN

matthew-andrews avatar matthew-andrews commented on May 30, 2024 1
Getting referenceerror: self is not defined when running mocha tests in command line as soon as I attempt to use isomorphic-fetch

from isomorphic-fetch.

Comments (15)

ericlau-solid avatar ericlau-solid commented on May 30, 2024 1

My workaround right now is to use webpack's providerPlugin to load fetch for dev, deploy, but not test (separate webpack.config file for each env). That means of course that I cannot call actual fetch at all, but have to stub it via a mocking framework. This is all right for unit testing, but won't work for integration testing. Also disallows me from using sinon's fake server functionality (since that would require an actual fetch call).

from isomorphic-fetch.

billinghamj avatar billinghamj commented on May 30, 2024 1

@matthew-andrews seems to be uninterested in resolving this. As such, @lucasfeliciano created "fetch-everywhere" instead which is designed to work in every circumstance - https://github.com/lucasfeliciano/fetch-everywhere

from isomorphic-fetch.

montogeek avatar montogeek commented on May 30, 2024 1

@andrewmclagan Indeed :)

from isomorphic-fetch.

billinghamj avatar billinghamj commented on May 30, 2024

This issue also causes React Native to crash. The problem is if GitHub's library is loaded without a browser environment, self isn't defined. I believe React Native's packager will include the script even if it is not required.

from isomorphic-fetch.

Download avatar Download commented on May 30, 2024

Having this same issue... Should we exclude something from the build (webpack externals config) when building for Node to prevent this?

from isomorphic-fetch.

billinghamj avatar billinghamj commented on May 30, 2024

I got this fixed within GitHub's code (JakeChampion/fetch#253)

But my PR on this repo also needs to be merged to resolve this entirely: #63

from isomorphic-fetch.

Download avatar Download commented on May 30, 2024

Much obliged @billinghamj ! Just wait for the merge I guess

from isomorphic-fetch.

lucasfeliciano avatar lucasfeliciano commented on May 30, 2024

Yeah, I'm waiting for the merge as well. 👍

Since it is a quick fix I made the changes directly in the file on node_modules just to keep developing.

from isomorphic-fetch.

montogeek avatar montogeek commented on May 30, 2024

What is the status of this merge?

from isomorphic-fetch.

montogeek avatar montogeek commented on May 30, 2024

@billinghamj Yes, just testing it :) Thanks :D

from isomorphic-fetch.

ivnmaksimovic avatar ivnmaksimovic commented on May 30, 2024

Same self is not defined when trying to use command line mocha test and import fetch from 'isomorphic-fetch';

from isomorphic-fetch.

andrewmclagan avatar andrewmclagan commented on May 30, 2024

@matthew-andrews: Also experiencing this, is there no solid solution yet, or roadmap for this to be merged. The community seems to be drifting away from this lib in favour of fetch-everywhere simply due to this issue.

from isomorphic-fetch.

marktrobinson avatar marktrobinson commented on May 30, 2024

I'm still getting this issue

my solution: lucasfeliciano/fetch-everywhere#7

from isomorphic-fetch.

noamshay avatar noamshay commented on May 30, 2024

i had this error working with chai/mocha test.
fixed by this workaround:
add fix-global-self.js with:
global.self = global;
module.exports = global;

then import it at the top of my test:
import "./fix-global-self"

works for me.

from isomorphic-fetch.

LucasUnplugged avatar LucasUnplugged commented on May 30, 2024

Another solution is to make sure node has a self property, via: https://www.npmjs.com/package/node-self.

from isomorphic-fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.