Skip to content

Commit 18b29d2

Browse files
authored
fix(build): Prevent rollup from adding [Symbol.toStringTag]: 'Module' to CJS files (#6043)
As of version 2.69.0, setting `output.generatedCode` to `'es2015'` (as we do) causes Rollup to [add `[Symbol.toStringTag]: 'Module'` to generated CJS files](rollup/rollup#4378 (comment)). Though this is valid ES6, it causes Jest to be unable to mock our generated packages. Though [a PR](jestjs/jest#13513) has been opened to fix this, the change almost certainly won't be backported, so anyone using Jest 29.2.2 or under will run into [this problem](#5994) if they try to mock `@sentry/xxx` 7.16. (The relevant change was introduced in #5951, when we (semi-)accidentally upgraded Rollup from 2.67.1 to 2.78.0, and was first included in version 7.16.) This PR prevents the new Rollup behavior, since it has no known benefit. (The [Rollup docs](https://rollupjs.org/guide/en/#outputgeneratedcode) say that presence of the `'Module'` toStringTag "is used for feature detection in certain libraries and frameworks," but not having it hasn't seemed to hurt us so far.)
1 parent b5497c7 commit 18b29d2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

rollup/npmHelpers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ export function makeBaseNPMConfig(options = {}) {
4444
// output individual files rather than one big bundle
4545
preserveModules: true,
4646

47-
// any wrappers or helper functions generated by rollup can use ES6 features
48-
generatedCode: 'es2015',
47+
// Allow wrappers or helper functions generated by rollup to use any ES6 features except symbols. (Symbols in
48+
// general are fine, but the `[Symbol.toStringTag]: 'Module'` which Rollup adds alongside `__esModule:
49+
// true` in CJS modules makes it so that Jest <= 29.2.2 crashes when trying to mock generated `@sentry/xxx`
50+
// packages. See https://github.com/getsentry/sentry-javascript/pull/6043.)
51+
generatedCode: {
52+
preset: 'es2015',
53+
symbols: false,
54+
},
4955

5056
// don't add `"use strict"` to the top of cjs files
5157
strict: false,

0 commit comments

Comments
 (0)