Repository navigation
Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.4.0
Framework Version
No response
Link to Sentry event
No response
SDK Setup
Sentry.init({
dsn: 'https://00000000000000000000000000000000@0000000.ingest.us.sentry.io/0000000',
integrations: [Sentry.nativeNodeFetchIntegration()],
});Steps to Reproduce
- Run the SDK setup in debug mode in a commonjs environment such as
jest - add breakpoint in
node_modules/@sentry/node/cjs/integrations/node-fetch.json the lineconst pkg = await import('opentelemetry-instrumentation-fetch-node');
Expected Result
It correctly imports opentelemetry-instrumentation-fetch-node without throwing an error in cjs mode
Actual Result
It throws an error
TypeError: A dynamic import callback was invoked without --experimental-vm-modules
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:226:11)
at getInstrumentation (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/integrations/node-fetch.ts:51:19)
at Object.setupOnce (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/integrations/node-fetch.ts:85:7)
at setupIntegration (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/integration.ts:122:105)
at /Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/integration.ts:93:7
at Array.forEach (<anonymous>)
at Object.setupIntegrations (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/integration.ts:90:16)
at NodeClient.setupIntegrations [as _setupIntegrations] (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/baseclient.ts:554:20)
at NodeClient.init (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/baseclient.ts:313:12)
at _init (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/sdk/init.ts:170:12)
at Object.init (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/node_modules/@sentry/src/sdk/init.ts:101:10)
at Object.init (/Users/bert.degeyter/dev/showpad-typescript/packages/sentry-utils/src/lib/before-breadcrumb.spec.ts:17:20)
at Promise.then.completed (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/utils.js:298:28)
at new Promise (<anonymous>)
at callAsyncCircusFn (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/utils.js:231:10)
at _callCircusHook (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/run.js:281:40)
at _runTestsForDescribeBlock (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/run.js:95:7)
at _runTestsForDescribeBlock (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/run.js:121:9)
at _runTestsForDescribeBlock (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/run.js:121:9)
at run (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/run.js:71:3)
at runAndTransformResultsToJestFormat (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
at jestAdapter (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
at runTestInternal (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-runner/build/runTest.js:367:16)
at runTest (/Users/bert.degeyter/dev/showpad-typescript/node_modules/jest-runner/build/runTest.js:444:34)
Metadata
Metadata
Assignees
Labels
No labels
Projects
- StatusShow more project fieldsWaiting for: Product Owner

Activity
mydea commentedon May 27, 2024
So what is the actual problem here? It seems that this is a problem with the env not supporting lazy loading properly. If this is not loaded in jest it's probably not a problem, or are you actually having a problem because of this in your app? Is this only happening in test env, for example?
TheHolyWaffle commentedon May 27, 2024
Hi @mydea Apologies if this isn't well defined.
For more context, I maintain a
beforeBreadcrumbfunction in our company and I'd like to test it's behavior using jest. I leveragesentry-testkitfor that but I noticed the breadcrumbs are not coming through anymore when upgrading from v7 to v8.The reason it fails is because it fails to load the native node fetch integration during the jest
beforeEach. (The stacktrace from above). I'd like to get this functioning again 🙏Here's the bigger context:
mydea commentedon May 27, 2024
Ah, OK, I can see the problem now.
Honestly I don't think there is an easy way to solve this in the SDK side of things 🤔 did you try to follow docs in jest here: https://jestjs.io/docs/ecmascript-modules for this?
[-]Sentry.nativeNodeFetchIntegration fails to import opentelemetry-instrumentation-fetch-node in cjs[/-][+]Sentry.nativeNodeFetchIntegration fails to import opentelemetry-instrumentation-fetch-node in jest[/+]TheHolyWaffle commentedon May 27, 2024
I can run the tests using
NODE_OPTIONS=--experimental-vm-modules npx jestwhich makes it succeed.But I'm wondering if this isn't also an issue in other cjs environments (besides Jest) where one might forget to use the
--experimental-vm-modulesflag?mydea commentedon May 27, 2024
So this should work just fine in true cjs apps (we have a bunch of tests covering this, and this is actually what makes this work normally for almost all apps, as the vast majority of apps out there is running in CJS mode as of now). I think it's really just a jest issue which does not properly support all of these things (yet), unfortunately 🤔 See #12137 for tests for this, which all run in CJS.
It's good to know that this flag fixes it, at least! 🙏
I would close this issue for now as there really isn't much we can do about this I believe!
TheHolyWaffle commentedon May 27, 2024
I agree, this is
jestspecific problem and using the vm flag fixes it. I should really spend the time to switch to something likevitest....Thanks for spending some time on this anyway 🙏 @mydea