expo-cli icon indicating copy to clipboard operation
expo-cli copied to clipboard

`ReferenceError: self is not defined` after re-installing npm packages

Open apaatsio opened this issue 8 years ago • 5 comments

I have a fresh project using the tabs template and I'm getting ReferenceError: self is not defined after I re-install npm packages.

To reproduce:

  1. expo init foo (select tabs template)
  2. cd foo
  3. npm test (observe that tests work fine)
  4. rm -rf node_modules
  5. npm install
  6. npm test

Actual result:

 FAIL  __tests__/App-test.js
  ● Test suite failed to run

    ReferenceError: self is not defined

      at node_modules/whatwg-fetch/dist/fetch.umd.js:8:40
      at Object.<anonymous>.support.searchParams (node_modules/whatwg-fetch/dist/fetch.umd.js:2:66)
      at Object.<anonymous> (node_modules/whatwg-fetch/dist/fetch.umd.js:5:2)
      at Object.<anonymous> (node_modules/jest-expo/src/setup.js:7:47)

Expected result:

Tests pass.

Versions

  • expo 29.0.0
  • expo-cli 1.1.0
  • node 9.11.2
  • npm 5.6.0
  • yarn 1.9.4
  • OS: Linux Manjaro

apaatsio avatar Sep 10 '18 16:09 apaatsio

Try:

rm -rf node_modules npm i [email protected] --save npm install

iamnapo avatar Sep 11 '18 08:09 iamnapo

@iamnapo Thank you. That fixed the symptom. I wonder what the underlying problem is though. What does expo init do differently than npm install?

apaatsio avatar Sep 11 '18 09:09 apaatsio

I think this is the problem (isomorphic-fetch is a module expo uses). npm install installs the newly released v3 of whatwg-fetch, which seems to cause the problem, whereas expo init uses its own lockfile and installs a previous version.

iamnapo avatar Sep 11 '18 10:09 iamnapo

I added GLOBAL.self = GLOBAL to the top of my App.js file so I guess doing npm i [email protected] --save is better

corasan avatar Sep 13 '18 14:09 corasan

I tried this with the latest version of expo-cli and it doesn't appear to be a problem anymore.

image (after doing the rm -rf node_modules and npm install)

I'll close for now. But please reopen (and give more details) if you encounter this again!

ccheever avatar Oct 04 '19 02:10 ccheever