Skip to content

Commit e2d65a1

Browse files
antonisclaude
andauthored
test(core): Resolve @sentry/* to CJS builds in Jest (#6301)
As of JS SDK v10.58.0 the @sentry/* packages expose a `react-native` export condition pointing at their ESM build. The `react-native` Jest preset's test environment sets `customExportConditions = ['require', 'react-native']`, so Jest resolves that condition and loads untransformed ESM (including transitive subpaths like `@sentry/core/browser`), failing with "Unexpected token 'export'". Use a custom test environment that drops the `react-native` condition so these packages resolve to their CJS builds, as they did before 10.58.0. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b18a991 commit e2d65a1

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

packages/core/jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ module.exports = {
1515
],
1616
},
1717
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
18+
// As of v10.58.0 the JS SDK packages expose a `react-native` export condition that points at
19+
// their ESM build. The `react-native` Jest preset's test environment sets
20+
// `customExportConditions = ['require', 'react-native']`, so Jest resolves that condition and
21+
// loads untransformed ESM (including transitive subpaths like `@sentry/core/browser`), failing
22+
// with "Unexpected token 'export'". Use a test environment that drops the `react-native`
23+
// condition so these packages resolve to their CJS builds, as they did before the condition.
24+
testEnvironment: '<rootDir>/test/RNTestEnvironment.js',
1825
testPathIgnorePatterns: ['<rootDir>/test/e2e/', '<rootDir>/test/tools/', '<rootDir>/test/react-native/versions'],
1926
testMatch: ['**/*.test.(ts|tsx)'],
2027
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
const ReactNativeEnv = require('react-native/jest/react-native-env');
3+
4+
// Extends the `react-native` preset's test environment but drops the `react-native` export
5+
// condition. Since v10.58.0 the JS SDK packages expose a `react-native` condition pointing at
6+
// their ESM build; resolving it makes Jest load untransformed ESM. Dropping it makes them resolve
7+
// to their CJS builds (via the `require` condition), restoring the pre-10.58.0 behaviour.
8+
module.exports = class extends ReactNativeEnv {
9+
customExportConditions = ['require'];
10+
};

0 commit comments

Comments
 (0)