Skip to content

Jest encountered an unexpected token after upgrading from 0.70 to 0.71 #36342

@koch10

Description

@koch10

Description

After upgrading from expo SDK 47 to 48 and consequently upgrading react-native to 0.71.3, my jest tests are failing. The error is "Jest encountered an unexpected token" and the location can be seen in the screenshot.

image

I don't suspect that this has anything to do with firebase itself, but rather something to do with it being esm format.

After doing some(a lot) of trial and error i found that it breaks specifically between react-native@0.71.0-rc.2 and react-native@0.71.0-rc.3. That is, my jest tests pass just fine on 0.71.0-rc.2, but fail on 0.71.0-rc.3.

React Native Version

0.71.3

Output of npx react-native info

System:
OS: Windows 10 10.0.22621
CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
Memory: 1006.46 MB / 7.82 GB
Binaries:
Node: 18.14.2 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 9.5.0 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: Version 2021.1.0.0 AI-211.7628.21.2111.8193401
Visual Studio: 16.11.31911.196 (Visual Studio Community 2019)
Languages:
Java: 17.0.3.1 - C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.3 => 0.71.3
react-native-windows: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

Follow the guide on setting up an Expo project: https://docs.expo.dev/tutorial/create-your-first-app/
Then follow the guide on setting up jest for expo: https://docs.expo.dev/guides/testing-with-jest/

run "npx expo install firebase" in the terminal

Insert "import firebase from 'firebase/app';" into the App.test.js file

run "npm run test" in the terminal, and it should now give the error.

Snack, code example, screenshot, or link to a repository

Edit by @robhogan - example repro: https://github.com/robhogan/react-native-issue-36342

Here is the package.json

{
  "name": "jest",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)"
    ]
  },
  "dependencies": {
    "@expo/webpack-config": "^18.0.1",
    "expo": "~48.0.4",
    "expo-status-bar": "~1.4.4",
    "firebase": "^9.17.1",
    "jest-expo": "^48.0.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.71.3",
    "react-native-web": "~0.18.10",
    "jest": "^29.2.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "^18.0.28",
    "@types/react-test-renderer": "^18.0.0"
  },
  "private": true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions