Can't Find Variable Self


#1

Hi there,

For users creating new project with expo-cli or XDE, you will get red screen “Can’t Find Variable Self” after your first “yarn” or “npm install”. This is because of new “whatwg-fetch” 3.0.0 published yesterday (https://www.npmjs.com/package/whatwg-fetch).
So you just need to force dependency to previous version:

"whatwg-fetch": "^2.0.4"

It means put it in package.json as “dependency”. Manually, with “yarn add whatwg-fetch@2.0.4.” Or with “npm add whatwg-fetch@2.0.4”.

Everything should now work like a charm.

Hope this helps :wink:

UP: expo@30.0.1 added whatwg-fetch@2.0.4 as dependency. Problem is gone :wink:


Publishing upgraded Expo repo bricks existing standalone apps? (29 to 30)
#2

Stupid question - is this done in package.json followed by an npm update? I can’t seem to downgrade the package…


#3

I use yarn. But yes, you can do it your way. Then verify in your package-lock.json (or yarn.lock for yarn user). You can go to node_modules/whatwg-fetch/package.json which version is installed. Is it working ?


#4

I was being a bit thick, a fresh npm install after downgrading the package fixed my problem.

Thanks for the investigation - you’ve got me up and running again :smile: :


#5

Can you please elaborate ‘downgrading package’? I am facing the similar issue


#6

I have done as you said but still when i do npm install it is getting updated to 3.0.0


#7

In your screen, “whatwg-fetch” doesn’t show which version is installed. But it shows “whatwg-fetch” is required for “isomorphic-fetch”. You need to go “whatwg-fetch” on your package-lock.json. As you can see on top right of vscode, there are 4 results.


#8

I inserted the dependency in my package.json with:

“whatwg-fetch”: “^2.0.4”

Then I deleted my package-lock.json, my node_modules folder and re-ran npm install and everything worked again :slight_smile:


#9

Yes you have to put it in package.json. Manually, with “yarn add whatwg-fetch@2.0.4.” or with “npm add whatwg-fetch@2.0.4”


#10

thanks, I was struggling with this issue for a couple of days yet


#11

You are amazing! Thanks for the fix.


#12

The error is still there when using expo-cli@2.0.0. Thank you for the fix.


#13

The error doesn’t depend on expo-cli. This is because when you start new expo project, there is no package-lock.json or yarn.lock. So last version of whatwg-fetch@3.0.0 is installed. And this version has been published a few days ago. I think for now expo still requires whatwg-fetch@2.0.4.


#14

i ha ve the same problem… i have update expo 30 and i not have the whatwg-fetch@2.0.4. but i have the same problem. red screen and not find the self variable…


#15

Does forcing the dependency on whatwg-fetch@2.0.4 solved your problem ?


#16

yes, i need add whatwg-fetch@2.0.4 in my package. but the expo 30 is so slow… the location api are very slow in ios and android… this two release 29 and 30 are very bad… i stay in 28 for now! :slight_smile: thanks for the help


#17

thx it helped a lot!


#18

UP: expo@30.0.1 added whatwg-fetch@2.0.4 as dependency. Problem is gone :wink:


#19

Running app with 30.0.1. Works until I install other dependencies like, expo-three, expo-graphics. Then I get the “Can’t Find Variable Self” again. Then whatwg-fetch@3.0.0 gets brought back in.


#20

Hello there,

I have recently come across this problem. I did not use any “whatwg-fetch” module but still, there is an error regarding “appRegistry” and “variable self” ONLY IN PRODUCTION. In my case, it was with the import format of a library.I found this after hours of random testing. Hope someone finds this useful

I had imported nanoid as - const nanoGenerator = “require(“nanoid/generate”)” (similar to nodejs)
nanoid is not supported in react native and I replaced it with my own function

I think you should also watch for the import statements in case you came across the same error