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

jest-expo tests fails with "ReferenceError: self is not defined" #2192

Closed
asgerhallas opened this issue Sep 11, 2018 · 4 comments
Closed

jest-expo tests fails with "ReferenceError: self is not defined" #2192

asgerhallas opened this issue Sep 11, 2018 · 4 comments

Comments

@asgerhallas
Copy link

asgerhallas commented Sep 11, 2018

Environment

Environment:
OS: Windows 10
Node: 8.11.4
Yarn: 1.3.2
npm: 6.4.1
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found

Packages: (wanted => installed)
expo: ^29.0.0 => 29.0.0
react: 16.3.1 => 16.3.1
react-native: expo/react-native#sdk-29 => 0.55.4

Steps to Reproduce

  1. Run create-react-native-app (+ install)
  2. Run yarn test: everything runs as expected
  3. Upgrade expo package from 27.0.0 to 29.0.0 (including corresponding react-native package and jest-expo)
  4. Run yarn test: all tests crash with "ReferenceError: self is not defined"

Stacktrace:

  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 Behavior

Tests would run successfully.

Actual Behavior

All tests crash with "ReferenceError: self is not defined"

@asgerhallas
Copy link
Author

Changing this line in jest-expo/src/setup.js:

const { Response, Request, Headers, fetch } = require('whatwg-fetch');

to:

const { Response, Request, Headers, fetch } = require('isomorphic-fetch');

...seems to solve the problem.

@apaatsio
Copy link

Fix without modifying any code:

rm -rf node_modules
npm install whatwg-fetch@2.0.4 --save
npm install

Related items:

@asgerhallas
Copy link
Author

Thanks, that worked. And thanks for the background info too!

dschlitt referenced this issue in vlexaargas/ggby-mobile Oct 1, 2018
error caused by a package requiring a version of fetch expecting the self global variable to be in scope (and it wasnt)
reinhard added a commit to Indoqa/indoqa-webpack that referenced this issue Oct 8, 2018
@Filipoz
Copy link

Filipoz commented Jan 8, 2019

Hi everyone. I've been trying to fix this issue in my project for some time already but with no success.
I already removed all the files and reinstalled with Yarn with whatwg-fetch@2.0.4 but had no success.
Can anyone help me?

I have no big changes to my project yet and inited with Expo. Here's my package.json:

  "private": true,
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "^31.0.2",
    "mappersmith": "^2.26.0",
    "moment": "^2.23.0",
    "native-base": "^2.8.1",
    "pagarme": "^3.9.0",
    "react": "16.5.0",
    "react-native": "0.57.1",
    "react-native-base64": "^0.0.2",
    "react-native-flash-message": "^0.1.10",
    "react-native-masked-text": "^1.9.2",
    "react-native-rsa-native": "^1.0.24",
    "react-native-shadow": "^1.2.2",
    "react-native-vector-icons": "^6.1.0",
    "react-native-webview": "^2.14.3",
    "react-navigation": "3.0.0",
    "react-redux": "^5.1.1",
    "redux": "^4.0.1",
    "whatwg-fetch": "2.0.4"
  },
  "devDependencies": {
    "babel-eslint": "^10.0.1",
    "babel-plugin-module-resolver": "3.1.1",
    "babel-preset-expo": "^5.0.0",
    "eslint": "4.12.1",
    "eslint-config-prettier": "2.9.0",
    "eslint-plugin-prettier": "2.6.0",
    "eslint-plugin-promise": "3.6.0",
    "eslint-plugin-react": "^7.11.1",
    "pino-pretty": "2.2.3",
    "prettier": "1.10.2"
  }
}```

@lock lock bot added the outdated label Jul 7, 2019
@lock lock bot locked and limited conversation to collaborators Jul 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants