expo: Expo 31 Jest transform error repro in tabs project template

Expo CLI 2.2.5

  1. expo init expo-31-project, choose tabs
  2. rm -rf node_modules && npm i
  3. npx jest
  4. Jest error:
Jest encountered an unexpected token

expo-31-project/node_modules/expo/build/environment/logging.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { Constants } from 'expo-constants';

SyntaxError: Unexpected token {
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
      at Object.<anonymous> (node_modules/expo/build/Expo.js:284:1)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 23 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @artyorsh for sharing, unfortunately your repo might be a bit confusing for someone that doesn’t want all the typescript stuff, as that is a significant part of your jest configuration.

The only thing that actually seems to be needed is:

installed jest-expo (not jest!) jest.config.js file:

module.exports = {
  preset: 'jest-expo',
  transform: {
    '\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
  }
};

leave the babel.config.js the way it was

@Overtorment @metz0r Please try and let me know if that helps.

My package.json:

{
  "name": "empty-project-template",
  "main": "node_modules/expo/AppEntry.js",
  "private": true,
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "test": "jest"
  },
  "dependencies": {
    "expo": "^31.0.2",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.0.0",
    "jest-expo": "^31.0.0"
  }
}

Still having this issue even after creating a brand new project with tabs using expo.

npm version: 6.2.0 node version: 10.9.0

See image

@bruno-edo answered my question here. The basic gist is use yarn instead of npm. Seems like the Expo dev’s didn’t test their code with npm and npm messes things up.

@c316 Thank you for bringing that up. I updated the original comment with my approach to using the workaround: https://github.com/expo/expo/issues/2595#issuecomment-443193112

@freeatnet it isn’t clear how to use that workaround. Can you post some more information on how to implement that workaround?

Hey! It looks like npm installs different dependencies versions than yarn, try installing deps with yarn. 🙂