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 — Unexpected token errors coming from import-in-the-middle · Issue #12422 · getsentry/sentry-javascript

Unexpected token errors coming from import-in-the-middle #12422

New issue
Copy link
New issue
Copy link
Closed
Closed
Unexpected token errors coming from import-in-the-middle#12422
Copy link
Assignees
timfish
Labels
Package-Meta: OpenTelemetry
Milestone
v8 Instrumentation Issues

Description

@SerenModz21
SerenModz21
opened on Jun 8, 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.8.0

Framework Version

Node v20.14.0

Link to Sentry event

No response

SDK Setup

Sentry.init({
    dsn: envParseString("SENTRY_DSN"),
    integrations: [
        Sentry.nativeNodeFetchIntegration(),
        Sentry.consoleIntegration(),
        Sentry.onUncaughtExceptionIntegration(),
        Sentry.onUnhandledRejectionIntegration(),
        Sentry.functionToStringIntegration(),
        Sentry.modulesIntegration(),
        Sentry.linkedErrorsIntegration(),
        Sentry.httpIntegration(),
    ],
    tracesSampleRate: 1.0,
    environment: nodeEnvironment,
    release: `${name}@${version}`,
});

Steps to Reproduce

I simply had migrated from v7 to v8.

I was using 8.7.0 with globalThis._sentryEsmLoaderHookRegistered = true; until the "no such file or directory" got issue, which was the case with 8.8.0. Since installing the update, i commented out that line of code to check if everything had been fixed but i get spammed with the mentioned unexpected token errors.

Just like the "no such file or directory" error, i'm just gonna have to keep using globalThis._sentryEsmLoaderHookRegistered = true; or just fallback to v7 for the time being.

There is #12357 which is quite similar, the difference being that I do not use TSX but the standard TypeScript compiler. Where my startup is simly tsc && node --enable-source-maps .. In addition, my project involves discord.js, @sapphire/framework, and other sapphire plugins/utilities (eg. decorators)

Expected Result

Errors should not appear.

Actual Result

SyntaxError [Error]: Unexpected token (3:40)
    at pp$4.raise (PATH_REDACTED\node_modules\acorn\dist\acorn.js:3573:15)
    at pp$9.unexpected (PATH_REDACTED\node_modules\acorn\dist\acorn.js:772:10)
    at pp$9.semicolon (PATH_REDACTED\node_modules\acorn\dist\acorn.js:749:68)
    at Parser.parseImport (PATH_REDACTED\node_modules\acorn-import-attributes\lib\index.js:242:12)
    at pp$8.parseStatement (PATH_REDACTED\node_modules\acorn\dist\acorn.js:948:51)
    at pp$8.parseTopLevel (PATH_REDACTED\node_modules\acorn\dist\acorn.js:829:23)
    at Parser.parse (PATH_REDACTED\node_modules\acorn\dist\acorn.js:601:17)
    at Function.parse (PATH_REDACTED\node_modules\acorn\dist\acorn.js:651:37)
    at getEsmExports (PATH_REDACTED\node_modules\@opentelemetry\instrumentation\node_modules\import-in-the-middle\lib\get-esm-exports.js:37:23)     
    at getExports (PATH_REDACTED\node_modules\@opentelemetry\instrumentation\node_modules\import-in-the-middle\lib\get-exports.js:73:12) {    
  pos: 166,
  loc: { line: 3, column: 40 },
  raisedAt: 170
}

Activity

Next
  1. SerenModz21
    added
    Type: Bug
    on Jun 8, 2024
  2. getsantry
    added
    Waiting for: Product Owner
    on Jun 8, 2024
  3. getsantry
    added this to GitHub Issues with 👀 3on Jun 8, 2024
  4. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 8, 2024
  5. github-actions
    added
    Package: node
    on Jun 8, 2024
  6. Lms24 commented on Jun 10, 2024

    @Lms24
    Lms24
    on Jun 10, 2024
    Member
    More actions

    Hi @SerenModz21 thanks for writing in and sorry for the troubles! I'm not yet sure how or why this error is thrown, especially because just transpiling with TSC shouldn't have an impact here. To debug this further:

    • Just to confirm: Your're transpiling your code to ESM ("import" syntax), correct?
    • which installation method of the Node SDK are you using?
      • related, are you passing the --import when you're starting your application as documented in the ESM-specific guides?

    Let's first check if the SDK is set up correctly and go from there.

  7. getsantry
    removed
    Waiting for: Product Owner
    on Jun 10, 2024
  8. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 10, 2024
  9. SerenModz21 commented on Jun 10, 2024

    @SerenModz21
    SerenModz21
    on Jun 10, 2024
    Author
    More actions

    I do indeed transpile to ESM. As for installation, that would be the late initialization method. Unfortunately however, I made the mistake of not trying with --import @sentry/node/preload; therefore, I will give such a try and provide an update on any further news. I am just a little confused how auto-instrumentation would make a difference in this situation.

  10. getsantry
    added
    Waiting for: Product Owner
    on Jun 10, 2024
  11. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 10, 2024
  12. Lms24 commented on Jun 10, 2024

    @Lms24
    Lms24
    on Jun 10, 2024
    Member
    More actions

    The --import @sentry/node/preload option ensures that import-in-the-middle and OpenTelemetry instrumentation is added early enough. I'm not sure if it makes a difference with your issue but IITM has been known for interfering with import syntax. Let's see if it changes something!

  13. getsantry
    removed
    Waiting for: Product Owner
    on Jun 10, 2024
  14. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 10, 2024
  15. timfish commented on Jun 10, 2024

    @timfish
    timfish
    on Jun 10, 2024
    Collaborator
    More actions

    It could be the --enable-source-maps option which I have a suspicion could be implemented via loader hooks or at least hits the resolution hook.

    I guess import-in-the-middle should be passing non-js files straight through to the next loader. Maybe if there are any exceptions iitm should console.error them but fall back to the next loader rather than fail at this point. It would make it less of a blocker when it fails on things like this.

  16. 48 remaining items

  17. mydea
    removed
    Waiting for: Product Owner
    on Jun 19, 2024
  18. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 19, 2024
  19. FozzieHi commented on Jul 7, 2024

    @FozzieHi
    FozzieHi
    on Jul 7, 2024
    More actions

    @timfish I'm experiencing a similar issue, do you think this is related?

    Error: 'import-in-the-middle' failed to wrap 'file:///app/node_modules/zlib-sync/index.js'
        at getSource (/app/node_modules/import-in-the-middle/hook.js:304:21)
        at async load (/app/node_modules/import-in-the-middle/hook.js:319:26)
        at async nextLoad (node:internal/modules/esm/hooks:866:22)
        at async Hooks.load (node:internal/modules/esm/hooks:449:20)
        at async handleMessage (node:internal/modules/esm/worker:196:18) {
      cause: Error: Unexpected closing brace.
        at @:4:142
          at parseSource (/app/node_modules/cjs-module-lexer/lexer.js:185:17)
          at parseCJS (/app/node_modules/cjs-module-lexer/lexer.js:43:5)
          at getCjsExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:37:20)
          at getExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:100:12)
          at async /app/node_modules/import-in-the-middle/lib/get-exports.js:48:28
          at async Promise.all (index 0)
          at async getCjsExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:40:5)
          at async processModule (/app/node_modules/import-in-the-middle/hook.js:131:23)
          at async getSource (/app/node_modules/import-in-the-middle/hook.js:269:25)
          at async load (/app/node_modules/import-in-the-middle/hook.js:319:26) {
        loc: 973
      }
    }

    Is this an issue within import-in-the-middle or Sentry's implementation of it? I'm happy to open an issue wherever.

  20. getsantry
    added
    Waiting for: Product Owner
    on Jul 7, 2024
  21. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 7, 2024
  22. timfish commented on Jul 7, 2024

    @timfish
    timfish
    on Jul 7, 2024
    Collaborator
    More actions

    @FozzieHi I think this is just a warning being logged. Does this affect your application otherwise?

  23. getsantry
    removed
    Waiting for: Product Owner
    on Jul 7, 2024
  24. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 7, 2024
  25. FozzieHi commented on Jul 7, 2024

    @FozzieHi
    FozzieHi
    on Jul 7, 2024
    More actions

    @FozzieHi I think this is just a warning being logged. Does this affect your application otherwise?

    It does seem to yes, zlib-sync is not used by me directly but discord.js uses it for compression, and it logs out this below the import-in-the-middle error:

    WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress

  26. getsantry
    added
    Waiting for: Product Owner
    on Jul 7, 2024
  27. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 7, 2024
  28. AbhiPrasad commented on Jul 8, 2024

    @AbhiPrasad
    AbhiPrasad
    on Jul 8, 2024
    Contributor
    More actions

    @FozzieHi mind opening a new issue? We can dive deeper there.

    For everyone else:

    With the newest release of import-in-the-middle v1.9.0 this should be fixed.

    If you upgrade to a fresh install of the latest version of the Node SDK it should use [email protected] by default.

  29. AbhiPrasad
    closed this as completedon Jul 8, 2024
  30. getsantry
    removed
    Waiting for: Product Owner
    on Jul 8, 2024
  31. FozzieHi commented on Jul 8, 2024

    @FozzieHi
    FozzieHi
    on Jul 8, 2024
    More actions

    @AbhiPrasad Will do, thanks for your work on this though!

    Reacted by Abhijeet Prasad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @timfish
    timfish

Labels

Package-Meta: OpenTelemetry

Projects

  • GitHub Issues with 👀 3
    Status
    Waiting for: Product Owner
    Show more project fields

Milestone

  • v8 Instrumentation Issues

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.