Skip to content

Commit 1946283

Browse files
committed
Fix esm...
1 parent 99a9d0f commit 1946283

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
makeSetSDKSourcePlugin,
1818
makeSucrasePlugin,
1919
} from './plugins/index.mjs';
20+
import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs';
2021
import { mergePlugins } from './utils.mjs';
2122

2223
const packageDotJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' }));
@@ -120,7 +121,7 @@ export function makeBaseNPMConfig(options = {}) {
120121
export function makeNPMConfigVariants(baseConfig) {
121122
const variantSpecificConfigs = [
122123
{ output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } },
123-
{ output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm') } },
124+
{ output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), plugins: [makePackageNodeEsm()] } },
124125
];
125126

126127
return variantSpecificConfigs.map(variant => deepMerge(baseConfig, variant));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Outputs a package.json file with {type: module} in the root of the output directory so that Node
3+
* treats .js files as ESM.
4+
*/
5+
export function makePackageNodeEsm() {
6+
return {
7+
name: 'make-package-node-esm',
8+
generateBundle() {
9+
this.emitFile({
10+
type: 'asset',
11+
fileName: 'package.json',
12+
source: '{ "type": "module" }',
13+
});
14+
},
15+
};
16+
}

packages/node-experimental/src/integrations/tracing/prisma.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { registerInstrumentations } from '@opentelemetry/instrumentation';
2-
import { PrismaInstrumentation } from '@prisma/instrumentation';
2+
// When importing CommonJs modules into an ESM module, we import the named exports directly.
3+
import * as prismaInstrumentation from '@prisma/instrumentation';
34
import { defineIntegration } from '@sentry/core';
45
import type { IntegrationFn } from '@sentry/types';
56

@@ -10,7 +11,7 @@ const _prismaIntegration = (() => {
1011
registerInstrumentations({
1112
instrumentations: [
1213
// does not have a hook to adjust spans & add origin
13-
new PrismaInstrumentation({}),
14+
new prismaInstrumentation.PrismaInstrumentation({}),
1415
],
1516
});
1617
},

packages/node-experimental/src/sdk/init.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import { defaultStackParser, getSentryRelease } from './api';
3939
import { NodeClient } from './client';
4040
import { initOtel } from './initOtel';
4141

42+
function getCjsOnlyIntegrations(isCjs = typeof require !== 'undefined'): Integration[] {
43+
return isCjs ? [nativeNodeFetchIntegration(), modulesIntegration()] : [];
44+
}
45+
4246
/** Get the default integrations for the Node Experimental SDK. */
4347
export function getDefaultIntegrations(options: Options): Integration[] {
4448
// TODO
@@ -51,17 +55,15 @@ export function getDefaultIntegrations(options: Options): Integration[] {
5155
// Native Wrappers
5256
consoleIntegration(),
5357
httpIntegration(),
54-
nativeNodeFetchIntegration(),
5558
// Global Handlers
5659
onUncaughtExceptionIntegration(),
5760
onUnhandledRejectionIntegration(),
5861
// Event Info
5962
contextLinesIntegration(),
6063
localVariablesIntegration(),
6164
nodeContextIntegration(),
62-
modulesIntegration(),
6365
httpIntegration(),
64-
nativeNodeFetchIntegration(),
66+
...getCjsOnlyIntegrations(),
6567
...(hasTracingEnabled(options) ? getAutoPerformanceIntegrations() : []),
6668
];
6769
}

0 commit comments

Comments
 (0)