question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: self is not defined

See original GitHub issue

I’ve incorporated isomorphic-fetch into a library I made called react-reach and it works great in the browser however when I try it out in node I get the following error in my console:

module.exports = self.fetch.bind(self);
                 ^
ReferenceError: self is not defined

I’m not exactly sure why this is going on however heres the library code that uses isomorphic-fetch:

import fetch from 'isomorphic-fetch';

export function transport (path, query, queryParams, token) {
  return fetch(path, {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'content-type': 'application/json',
      'authorization': token
    },
    body: JSON.stringify({
      query,
      queryParams
    })
  })
  .then((response) => {
    return response.json();
  })
  .then((responseBody) => {
    if (responseBody && responseBody.errors) {
      throw new Error(responseBody.errors);
    }
    return responseBody.data;
  });
}

Here is the userland code used in node:

import { reachGraphQL } from 'react-reach';

var imgUri = `http://localhost:8080/users/${req.params.id}/${req.file.originalname}`;

reachGraphQL(`http://localhost:8080/`, `mutation {
  profilePic: updateUser(profilePicture: "${imgUri}"){
    profilePicture
  }
}`)

If you know why this may be occurring please let me know as I depend on this library for an application at my job.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

16reactions
HoraceShmoracecommented, May 5, 2017

Wait, this isn’t a solution. Now it’s not available in your build.

12reactions
marrcommented, Aug 3, 2016

Is this a regression with webpack v2? I have been previously been able to bundle isomorphic-fetch with webpack, now that I’ve upgrade to v2 beta I am seeing the self error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript + Webpack library generates "ReferenceError
This issue is related to the option output.globalObject of which is described here. I believe webpack has set it as self for a...
Read more >
ReferenceError: self is not defined · Issue #2172
bug report When building with parceljs where node-fetch is required, the below error is thrown when running the compiled js Configuration ...
Read more >
ReferenceError: self is not defined - Technical
This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it...
Read more >
node-self
Start using node-self in your project by running `npm i ... But, in Node.js console.log(self); // ReferenceError: self is not defined.
Read more >
NextJS ReferenceError: self is not defined
Hi everyone,. I keep getting error every time I refresh the page that renders the map. I'm using the “@tomtom-international/web-sdk-maps” and “@ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found