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

Document how to use Node SDK with ESM + loader #11395

Closed
Tracked by #11064
lforst opened this issue Apr 3, 2024 · 6 comments
Closed
Tracked by #11064

Document how to use Node SDK with ESM + loader #11395

lforst opened this issue Apr 3, 2024 · 6 comments
Labels
Package: node Issues related to the Sentry Node SDK

Comments

@lforst
Copy link
Member

lforst commented Apr 3, 2024

Generally, this is blocked by open-telemetry/opentelemetry-js#4547 (comment)

After that is resolved we should document how to use the esm loader. It should be the following:

  • Node <=18.18.2: node --experimental-loader=@sentry/node/hook app.js
  • Node >=18.19.0: node --import=@sentry/node/register app.js
@AbhiPrasad AbhiPrasad added the Package: node Issues related to the Sentry Node SDK label Apr 10, 2024
@mydea mydea closed this as completed May 15, 2024
@lilouartz
Copy link

How do I combine this with tsx?

@lilouartz
Copy link

tsx --import=@sentry/node/register app/bin/server.ts

is giving error:

Package subpath './register' is not defined by "exports"

@lilouartz
Copy link

node --import=@sentry/node/import --import tsx app/bin/server.ts

gives

node:internal/modules/run_main:125
    triggerUncaughtException(
    ^
SyntaxError [Error]: Unexpected token (12:14)

@lilouartz
Copy link

node --import tsx --import=@sentry/node/import app/bin/server.ts

gives

node:internal/modules/run_main:125
    triggerUncaughtException(
    ^
TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file

@mydea
Copy link
Member

mydea commented May 17, 2024

I believe that tsx just transpiles to CJS, so it should work to just follow these docs: https://docs.sentry.io/platforms/javascript/guides/node/install/commonjs/

and ensure to import & run Sentry.init() before importing anything else.
If that does not work for you, please open a new issue with as much details as possible about your app setup - thank you!

@lilouartz
Copy link

#12111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK
Projects
None yet
Development

No branches or pull requests

4 participants