Repository navigation
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.0.0
Framework Version
No response
Link to Sentry event
No response
SDK Setup
Sentry.init({
dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
});Steps to Reproduce
I've created a minimal reproduction here: https://github.com/nwalters512/sentry-v8-tsx-error-repro
- Clone the repository
- Install dependencies with
yarn - Run
yarn tsx src/index.ts - Observe that the process fails with the error
TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
Several observations that are hopefully helpful to y'all:
-
This only occurs when
"allowJs": trueis set intsconfig.json. As Sentry isn't concerned with this, that made me think this problem might actually be intsx. However... -
When adding instrumentation directly with the
@opentelemetry/*packages, everything works fine. This is reproducible by making the following change tosrc/index.ts:-import './instrument-sentry.js'; +import './instrument-opentelemetry.js';
Given this, I'm strongly inclined to believe that this is an issue with the way in which Sentry is using OpenTelemetry.
-
This only breaks for core Node modules like
util,fs, etc. Importing other modules works fine. For instance, the following change tosrc/index.tsmakes it work without erroring:-await import('util'); +await import('zod');
-
This only breaks for dynamic imports. For instance, the following change to
src/index.tsmakes it work without erroring:-await import('util'); +import 'util';
Expected Result
I would expect the process to complete successfully and log util imported!.
Actual Result
The process errors out while importing util and does not print util imported!.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Activity
timfish commentedon May 14, 2024
The full stack trace is:
And here is the bottom of the call stack.
Maybe the loader hook added by
import-in-the-middleis somehow clashing with the loader hooks added bytsx?timfish commentedon May 14, 2024
Looking at the stack trace, although
import-in-the-middleis at the bottom, further up we see frames fromtsx:I guess it's not handling the params the iitm adds to the url?
So I've opened an issue there:
privatenumber/tsx#554
[-]Sentry breaks dynamic import of core Node modules when running in tsx[/-][+]import hook incompatible with `tsx`[/+]nwalters512 commentedon May 14, 2024
@timfish thanks for investigating this; your small reproduction that used just
import-in-the-middlewas very helpful. I'm relatively confident that the issue here is in fact withimport-in-the-middleand the fact that it appends query parameters to the URL it returns from its resolvers. That is, consider this line:https://github.com/DataDog/import-in-the-middle/blob/00b01fff1f5b69dd25e307593ec54d1d8abb4844/hook.js#L259
Changing that to just
url: url.urlmakes your reproduction complete without error (though I have no idea what effect that has onimport-in-the-middleactually working).Specifically, it looks like the issue is that this URL with
?iitm=trueends up as theparentURLin a subsequent resolution, which you can see by addingconsole.log(specifier, context)immediately after https://github.com/privatenumber/tsx/blob/e2afc60bbcc299e09a5bf0e0c8909b6766b633a2/src/esm/hook/resolve.ts#L39:timfish commentedon May 14, 2024
Tracing the resolving of the otel hooking, it looks like
?iitm=trueis used so that iitm knows that the resolving is actually coming from its hook rather than the original location.Adding the query to the parent URL should be fine as this is still a valid URL.
For example, the following code runs fine under both node and tsx:
and outputs:
node:util?iitm=trueis also a valid URL so I'm not fully convinced that's causing the issue yet!51 remaining items
timfish commentedon May 24, 2024
There are multiple outstanding PRs for
import-in-the-middle(including the one from @nwalters512 🙏) that combined hopefully fix a wide range of issues.Until they make it to a release, I've combined these into a patch that can be used with
patch-package:#12242 (comment)
If anyone can confirm that this fixes their issues that would be great!
Fix resolution of lib/register.js when using multiple loaders (#76)
lilouartz commentedon Jun 6, 2024
Does the fact that this PR is closed means that now Sentry is compatible with tsx?
AbhiPrasad commentedon Jun 6, 2024
This issue is still open #12357, but this specific issue is fixed.
Just needs to be released - that will come out tomorrow most likely.
feat: Upgrade OTEL dependencies (#12388)
mydea commentedon Jun 7, 2024
Hello, we've just released v8.8.0, which should hopefully resolve this ESM problem. Let us know if you updated and are still running into problems!
timfish commentedon Jun 7, 2024
This issue might be fixed, but unfortunately
tsxalways adds it's loaders before others passed via--importso it's still not compatible:#12357
privatenumber/tsx#571
import-in-the-middleparses the loaded code to find the imports and with the current order of the loaders,import-in-the-middleis passed TypeScript code which it cannot parse.feat: Upgrade OTEL dependencies (#12388)
damianobarbati commentedon May 13, 2025
@timfish I'm actually not using tsx or anything, only native nodejs type stripping: is there any solution for it?
Sentry init file:
Results in:
timfish commentedon May 13, 2025
A new version of
import-in-the-middlewas released today that should help with--experimental-strip-types.If you upgrade
import-in-the-middleor delete your lock file, you should get the new version.