Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using --import ./instrument.mjs and tsx fails #12357

Closed
3 tasks done
Tracked by #12485
AbhiPrasad opened this issue Jun 5, 2024 · 4 comments
Closed
3 tasks done
Tracked by #12485

using --import ./instrument.mjs and tsx fails #12357

AbhiPrasad opened this issue Jun 5, 2024 · 4 comments
Assignees
Labels

Comments

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Jun 5, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.7.0

Framework Version

Node v20.14.0

Link to Sentry event

No response

SDK Setup

Sentry.init({ dsn, tracesSampleRate: 1.0 });

Steps to Reproduce

"NODE_OPTIONS='--import ./instrument.mjs' doppler run -- tsx src/index.ts"

Discord thread: https://discord.com/channels/621778831602221064/1247628587176034324/1247628587176034324

Expected Result

Does not cause an error

Actual Result

> NODE_OPTIONS='--import ./instrument.mjs' doppler run -- tsx watch src/index.ts

SyntaxError [Error]: Unexpected token (5:9)
    at pp$4.raise (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:3573:15)
    at pp$9.unexpected (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:772:10)
    at pp$9.expect (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:766:28)
    at pp$7.parseBindingList (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:2077:19)
    at pp$8.parseFunctionParams (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:1386:24)
    at pp$8.parseFunction (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:1375:10)
    at Parser.parseExport (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn-import-attributes@1.9.5_acorn@8.11.3/node_modules/acorn-import-attributes/lib/index.js:172:35)
    at pp$8.parseStatement (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:948:76)
    at pp$8.parseTopLevel (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:829:23)
    at Parser.parse (/Users/ollebergkvist/Documents/dev/projects/alpha-securities/api-crons/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:601:17) {
  pos: 179,
  loc: { line: 5, column: 9 },
  raisedAt: 180
}

Happens even when we pin import-in-the-middle to 1.8.0

@timfish
Copy link
Collaborator

timfish commented Jun 5, 2024

This appears to be because the tsx and import-in-the-middle loaders are registered in the wrong order. import-in-the-middle is being passed TypeScript which it was never designed to parse.

@timfish
Copy link
Collaborator

timfish commented Jun 5, 2024

privatenumber/tsx#571

@timfish
Copy link
Collaborator

timfish commented Jun 15, 2024

This should hopefully have been fixed by the numerous PRs recently merged at import-in-the-middle.

Specifically for tsx, import-in-the-middle now gracefully handles source code it can't parse by falling back to the parent loader. This does mean that iitm won't be able to hook TypeScript files but that's likely not much of a concern for now.

While we wait for this to be released, there is a patch available that combines all the fixes. If anyone can confirm this patch fixes this issue that would be super helpful!

@AbhiPrasad
Copy link
Member Author

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 import-in-the-middle@1.9.0 by default.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants