Jest test suite fails with "import outside scope" from expo/src/winter/runtime.native.ts

1 day ago 1
ARTICLE AD BOX

Problem

When running Jest tests in my Expo 54 / React Native project, one test suite consistently fails with the following error:

enter image description here The other tests in the suite run fine (16 passed, 4 failed all with this same error).

Environment

expo: ~54.0.33 jest-expo: ~54.0.0 react-native: 0.81.5 @testing-library/react-native: ^13.3.3 jest: ^29 react: 19.1.0 Node: 20.x, Windows 11

**3. Verified `expo-updates` is not imported anywhere** — confirmed with a project-wide search. Not the cause.

**4. Cleared Metro and Jest cache** (`--clearCache`, deleted `.expo` folder, restarted)


Current `jest.config.js`

/** * jest.config.js */ module.exports = { preset: 'jest-expo', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)', ], 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)" ], moduleNameMapper: { 'expo/src/winter/(.*)': '<rootDir>/tests/mocks/emptyMock.js', // Static assets '\\.(jpg|jpeg|png|gif|svg|ttf|woff|woff2)$': '<rootDir>/tests/mocks/fileMock.js', // Path alias — maps @/ to project root '^@/(.*)$': '<rootDir>/$1', }, setupFiles: ['<rootDir>/tests/mocks/setup.js'], collectCoverageFrom: [ 'context/**/*.{ts,tsx}', 'hooks/**/*.{ts,tsx}', 'services/**/*.{ts,tsx}', '!**/__tests__/**', '!**/*.d.ts', ], testTimeout: 10000, };
Read Entire Article