Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested React Native projects result in TypeError: undefined is not an object (evaluating self.fetch) #9599

Closed
migueloller opened this issue Aug 26, 2016 · 18 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@migueloller
Copy link

I'm unsure how related this is to #5667 or #3975 but I've been trying to figure this out for 5 hours.

Here's the repo: https://github.com/bloveit/react-native-redux-navigation

I'm trying to create a React Native example for this module but there is an error that occurs when trying to run the example.

To reproduce:

git clone https://github.com/bloveit/react-native-redux-navigation.git
cd react-native-redux-navigation
npm i
cd examples/TabsExample
npm i
react-native run-ios

I tried to pinpoint the error to a specific package, but no luck. I also tried nesting other React Native projects but the bug didn't happen (it seems to be an edge case).

Would greatly appreciate some insight on this bug!

Screenshot:
simulator screen shot aug 26 2016 1 39 12 am

Thanks! 🍺

@migueloller
Copy link
Author

A most peculiar thing is that if remote JS debugging is turned on, the error goes away.

@willks
Copy link

willks commented Sep 20, 2016

@migueloller I'm also getting this since trying to upgrade to RN 0.33 - and this is my latest issue. It works in DEBUG mode for me as well. Did you ever get around this issue?

@migueloller
Copy link
Author

@willks,

I did not. 😞

I ended up removing the example folder completely and was going to look at the problem a bit closer at a later time.

@willks
Copy link

willks commented Sep 21, 2016

@migueloller Hey I got it working using RN 0.33 and doing a hack - following this project:

https://github.com/johanneslumpe/react-native-browser-polyfill

Specifically, I added the following to my app.js:

global.self = global;

I added it right at the top. Now my fetches are working properly again. Seems like a dirty hack but I was a bit desperate to get it going on iOS10 and now it's running again.

@migueloller
Copy link
Author

@willks,

Interesting fix, I wonder if React Native should do this by itself?

@willks
Copy link

willks commented Sep 23, 2016

@migueloller Yeah there's a bit of powerful opinions either way so rather than wait until the respective teams make up their minds, I think the users have to solve this one on their own.

@compojoom
Copy link
Contributor

compojoom commented Nov 11, 2016

I had the same issue for the past 2 months and I was always wondering what's going on.

@willks - thanks, your fix works for me as well.

@compojoom
Copy link
Contributor

Actually I had to do this:

if(typeof global.self === "undefined")
{
    global.self = global;
}

because when debuging remotely I was getting: "cannot assign to read only property 'self' of object '#?"

@tqc
Copy link
Contributor

tqc commented May 17, 2017

This is caused by the fetch polyfill from https://github.com/github/fetch / https://www.npmjs.com/package/whatwg-fetch requiring self or this to be defined.

The workaround from other comments usually succeeds, but is not completely reliable because the packager/transpiler does not guarantee that that will run before whatever is calling fetch. Usually that isn't a problem because global.fetch is implemented as a lazy getter, but a module containing if (fetch) on startup is sufficient to trigger the bug.

@hramos hramos changed the title Nested React Native projects result in TypeError: undefined is not an object (evaluating self.fetch) Nested React Native projects result in TypeError: undefined is not an object (evaluating self.fetch) Jul 21, 2017
@pull-bot
Copy link

pull-bot commented Oct 9, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos added the Icebox label Oct 9, 2017
@hramos hramos closed this as completed Oct 9, 2017
davidvuong added a commit to davidvuong/ddfa-rn-app that referenced this issue Dec 4, 2017
@apolishch
Copy link

This issue has reappeared for me when upgrading from RN0.51 to RN0.53
The workaround in this commit:
davidvuong/ddfa-rn-app@e54a799

makes the problem go away

@iamlasse
Copy link

iamlasse commented Mar 4, 2018

I just opened my project this morning after working on it last night without problem to see this weird error... ANyone find a fix or workaround for this??

@alexfoxy
Copy link

alexfoxy commented Mar 5, 2018

I also have this issue all of a sudden. I have tried the global.self = global; fix to no avail. Running RN0.54

@nhannah
Copy link

nhannah commented Mar 27, 2018

I rebooted my computer and my react app went from running fine to only running with expo in debug as described. @apolishch 's referenced fix worked for me for now, but seems very odd that it came out of no where.

@MarkOSullivan94
Copy link

Also using a nested RN project and came across this issue in 0.55.4

@compojoom's solution fixed this for me: #9599 (comment)

@Calsowah
Copy link

Calsowah commented Aug 5, 2018

@alexfoxy where you able to find an alternative solution? I have also tried the global.self=global solution but am still having the same error

@paulmars
Copy link

Appearing for me.

"react": "^16.4.2",
"react-native": "~0.55.2",

@amitlibra
Copy link

I am noticing this issue only on Android

    "react": "16.4.2",
    "react-native": "0.55.4",

I used the above recommended fix:

if (global && !global.self && Platform.OS === 'android') {
  global.self = global;
}

@facebook facebook locked as resolved and limited conversation to collaborators Oct 9, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests