Skip to content

Commit 2a5e2b3

Browse files
committed
fix(gatsby): Use import for gatsby-browser.js instead of require
It seems that due to the `require` usage there, treeshaking is not working as expected. Just replacing this with using esm `import` seems to resolve this. I tried this in sentry-docs and a reproduction app and it seemed good to me.
1 parent de51011 commit 2a5e2b3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/gatsby/.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ module.exports = {
1515
project: ['../../tsconfig.dev.json'],
1616
},
1717
},
18+
{
19+
files: ['./gatsby-browser.js'],
20+
env: {
21+
browser: true,
22+
node: false,
23+
},
24+
parserOptions: {
25+
sourceType: 'module',
26+
},
27+
},
1828
],
1929
extends: ['../../.eslintrc.js'],
2030
};

packages/gatsby/gatsby-browser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
2-
const Sentry = require('@sentry/gatsby');
2+
import { init } from '@sentry/gatsby';
33

4-
exports.onClientEntry = function (_, pluginParams) {
4+
export function onClientEntry(_, pluginParams) {
55
const isIntialized = isSentryInitialized();
66
const areOptionsDefined = areSentryOptionsDefined(pluginParams);
77

@@ -24,12 +24,12 @@ exports.onClientEntry = function (_, pluginParams) {
2424
return;
2525
}
2626

27-
Sentry.init({
27+
init({
2828
// eslint-disable-next-line no-undef
2929
dsn: __SENTRY_DSN__,
3030
...pluginParams,
3131
});
32-
};
32+
}
3333

3434
function isSentryInitialized() {
3535
// Although `window` should exist because we're in the browser (where this script

0 commit comments

Comments
 (0)