GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — @simplewebauthn/server is not supported when using ESM · Issue #12996 · getsentry/sentry-javascript

@simplewebauthn/server is not supported when using ESM #12996

New issue
Copy link
New issue
Copy link
Closed
Closed
@simplewebauthn/server is not supported when using ESM#12996
Copy link
Assignees
timfishAbhiPrasad
Labels
Bug

Description

@P4sca1
P4sca1
opened on Jul 21, 2024
Issue body actions

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.19.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup/Reproduction Example

// Preloaded using node --import flag. Do not import code from other source files here.
// https://docs.sentry.io/platforms/javascript/guides/node/install/esm/
// @ts-check

import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import * as Sentry from '@sentry/node'
import { nodeProfilingIntegration } from '@sentry/profiling-node'

/**
 * The root directory of the application.
 * @see {@link https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/rewriteframes/}
 */
const root = dirname(fileURLToPath(import.meta.url))

const env =
	process.env['SENTRY_ENV'] || process.env['NODE_ENV'] || 'development'
const version = process.env['PACKAGE_VERSION']

Sentry.init({
	dsn: 'redacted',
	release: version ? `api@${version}` : undefined,
	environment: env,
	integrations: [
		nodeProfilingIntegration(),
		Sentry.dedupeIntegration(),
		Sentry.rewriteFramesIntegration({ root }),
		Sentry.prismaIntegration(),
	],
	beforeBreadcrumb: (breadcrumb) => {
		// Filter out writes to apollographql reporting API, because they are not helpful for error tracing
		// and spam breadcrumbs.
		if (
			breadcrumb.type === 'http' &&
			typeof breadcrumb.data?.['url'] === 'string' &&
			breadcrumb.data['url'].includes('api.apollographql.com')
		) {
			return null
		}

		return breadcrumb
	},
	tracesSampleRate: 0.1,
	profilesSampleRate: 0.1,
})

Steps to Reproduce

Install @simplewebauthn/server version 10.0.0.

import {
	generateAuthenticationOptions,
	generateRegistrationOptions,
	verifyAuthenticationResponse,
	verifyRegistrationResponse,
} from '@simplewebauthn/server'

Expected Result

Using @simplewebauthn/server using Sentry intstrumentation in an ESM environment should work.
Everything works fine when removing the --import ./instrument.js flag.

Actual Result

[nodemon] starting `node --env-file=.env --import ./instrument.js --import @swc-node/register/esm-register ./src/main.ts`
ReferenceError: generateChallenge is not defined
    at Function.assign (<anonymous>)
    at file:///Users/pascal/code/ips-hosting/api/node_modules/.pnpm/@[email protected]/node_modules/@simplewebauthn/server/esm/helpers/index.js?iitm=true:6:18
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:485:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5)

Activity

  1. P4sca1
    added
    Type: Bug
    on Jul 21, 2024
  2. getsantry
    added
    Waiting for: Product Owner
    on Jul 21, 2024
  3. getsantry
    added this to GitHub Issues with 👀 3on Jul 21, 2024
  4. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 21, 2024
  5. github-actions
    added
    Package: node
    on Jul 21, 2024
  6. mydea
    assigned
    AbhiPrasad
    and
    timfish
    on Jul 22, 2024
  7. mydea commented on Jul 23, 2024

    @mydea
    mydea
    on Jul 23, 2024
    Member
    More actions

    Hey,

    can you try to exclude this package from instrumentation - I just noticed this was not properly documented yet, so I added docs here getsentry/sentry-docs#10803

    So something like this:

    Sentry.init({
      registerEsmLoaderHooks: {
        // Provide a list of package names to exclude from instrumentation
        exclude: ["@simplewebauthn/server"],
      },
    });
  8. getsantry
    removed
    Waiting for: Product Owner
    on Jul 23, 2024
  9. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 23, 2024
  10. timfish commented on Jul 23, 2024

    @timfish
    timfish
    on Jul 23, 2024
    Collaborator
    More actions

    You might need to use a regular expression:

    Sentry.init({
      registerEsmLoaderHooks: {
        // Provide a list of package names to exclude from instrumentation
        exclude: [/@simplewebauthn\/server/],
      },
    });

    For regular expressions to work you'll need to ensure that v1.10.0 of import-in-the-middle is in your dependencies. I only released this a few moments ago so you will need to remove your lock file and re-install or run npm/yarn update import-in-the-middle to update to it.

    The Sentry type definitions don't yet allow regular expressions so I've opened a PR for that.

  11. P4sca1 commented on Jul 23, 2024

    @P4sca1
    P4sca1
    on Jul 23, 2024
    Author
    More actions

    Thank you for your help. After upgrading import-in-the-middle to v1.10.0 and adding the following to my Sentry.init options, I can confirm that using @simplewebauthn/server is now working.

    registerEsmLoaderHooks: {
    	// @ts-expect-error -- https://github.com/getsentry/sentry-javascript/pull/13016
    	exclude: [/@simplewebauthn\/server/],
    },

    It was indeed required to use regular expressions. Using "@simplewebauthn/server" did not work.

    Reacted by Tim Fish and Francesco Gringl-Novy
  12. getsantry
    added
    Waiting for: Product Owner
    on Jul 23, 2024
  13. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 23, 2024
  14. timfish commented on Jul 23, 2024

    @timfish
    timfish
    on Jul 23, 2024
    Collaborator
    More actions

    Thank you for confirming!

    We should hopefully have an update coming soon which will negate the need for this manual configuration.

    Reacted by Pascal Sthamer and Kent C. Dodds
  15. getsantry
    removed
    Waiting for: Product Owner
    on Jul 23, 2024
  16. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 23, 2024
  17. timfish commented on Sep 9, 2024

    @timfish
    timfish
    on Sep 9, 2024
    Collaborator
    More actions

    v8.29.0 of the Node SDK adds the new onlyIncludeInstrumentedModules option to registerEsmLoaderHooks.

    import * as Sentry from '@sentry/node';
    
    Sentry.init({
      dsn: '__PUBLIC_DSN__',
      registerEsmLoaderHooks: { onlyIncludeInstrumentedModules: true },
    });

    When set to true, import-in-the-middle will only wrap ESM modules that are specifically instrumented by OpenTelemetry plugins. This is useful to avoid issues where import-in-the-middle is not compatible with some of your dependencies.

    This feature will only work if you Sentry.init() the SDK before the instrumented modules are loaded. This can be achieved via the Node --register and --import CLI flags or by loading your app code via async import() after calling Sentry.init().

    Please let me know if this helps solve the import-in-the-middle incompatibility issues you are experiencing!

    Reacted by Pascal Sthamer
  18. AbhiPrasad
    removed
    Type: Bug
    on Sep 10, 2024
  19. AbhiPrasad commented on Nov 1, 2024

    @AbhiPrasad
    AbhiPrasad
    on Nov 1, 2024
    Contributor
    More actions

    Closing this for clean-up. If this issue still applies, please re-open. Thanks!

  20. AbhiPrasad
    closed this as completedon Nov 1, 2024
  21. kentcdodds commented on Feb 18, 2025

    @kentcdodds
    kentcdodds
    on Feb 18, 2025
    More actions

    Seems like it's still necessary to have some sort of config for avoiding this problem, even though I don't think there's anything particularly wrong with the @simplewebauthn/server package. Is this issue really complete?

    // breaks
    import * as Sentry from '@sentry/node'
    Sentry.init()
    
    await import('@simplewebauthn/server')
    // does not break
    // import * as Sentry from '@sentry/node'
    // Sentry.init()
    
    await import('@simplewebauthn/server')
    // does not break
    import * as Sentry from '@sentry/node'
    Sentry.init()
    
    // await import('@simplewebauthn/server')
    // does not break
    import * as Sentry from '@sentry/node'
    Sentry.init({
    	registerEsmLoaderHooks: { onlyIncludeInstrumentedModules: true },
    })
    
    await import('@simplewebauthn/server')
    

    I'm happy there is an option we can provide to avoid this problem, but... It seems wrong... There just seems to be something really wrong with the integration of these packages, and I'm not sure what it could be. But I feel like we should probably have a proper solution for it.

  22. ghost added
    Bug
    on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @AbhiPrasad
    AbhiPrasad
  • @timfish
    timfish

Labels

Bug

Projects

  • GitHub Issues with 👀 3
    Status
    No status
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.