Skip to content

Commit

Permalink
fix(build): Prevent rollup from adding `[Symbol.toStringTag]: 'Module…
Browse files Browse the repository at this point in the history
…'` 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.)
  • Loading branch information
lobsterkatie authored Oct 27, 2022
1 parent b5497c7 commit 18b29d2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rollup/npmHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ export function makeBaseNPMConfig(options = {}) {
// output individual files rather than one big bundle
preserveModules: true,

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

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

0 comments on commit 18b29d2

Please sign in to comment.