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

Incompatible with import-in-the-middle loader #554

Closed
5 of 6 tasks
timfish opened this issue May 14, 2024 · 4 comments
Closed
5 of 6 tasks

Incompatible with import-in-the-middle loader #554

timfish opened this issue May 14, 2024 · 4 comments

Comments

@timfish
Copy link

timfish commented May 14, 2024

Acknowledgements

  • I read the documentation and searched existing issues to avoid duplicates
  • I am reporting a confirmed bug (not seek debugging help)
  • I understand this is a collaborative project and relies on my contributions
  • I read and understood the Contribution guide

Problem & expected behavior (under 200 words)

With import-in-the-middle@1.7.1 and the following code

test.ts

import { register } from "node:module";
register("import-in-the-middle/hook.mjs", import.meta.url);
await import("node:util");

Running:

tsx test.ts

I get the following stack trace:

TypeError: The URL must be of scheme file
    at new NodeError (node:internal/errors:406:5)
    at fileURLToPath (node:internal/url:1393:11)
    at finalizeResolution (node:internal/modules/esm/resolve:234:42)
    at moduleResolve (node:internal/modules/esm/resolve:845:10)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at nextResolve (node:internal/modules/esm/hooks:833:28)
    at y (file:///Users/tim/Documents/Repositories/sentry-v8-tsx-error-repro/node_modules/tsx/dist/esm/index.mjs?1715697897382:128:19)
    at j (file:///Users/tim/Documents/Repositories/sentry-v8-tsx-error-repro/node_modules/tsx/dist/esm/index.mjs?1715697897382:191:20)
    at nextResolve (node:internal/modules/esm/hooks:833:28)
    at resolve (/Users/tim/Documents/Repositories/sentry-v8-tsx-error-repro/node_modules/import-in-the-middle/hook.js:94:23) 

If you disable allowJs this no longer errors.

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Supporting engineering work financially will speed up resolution

  • I'm willing to offer financial support
@privatenumber
Copy link
Owner

I'm going to close this temporarily for bug tracking purposes since the minimal reproduction should prove that the bug is in tsx rather than import-in-the-middle.

But don't let that deter you and feel free to investigate further. If you determine it's actually a bug in tsx, I'd be happy to accept a PR.

The published tsx code is minified, but the contribution guide has development tips on how you can turn it off and use the dev version:
https://github.com/privatenumber/tsx/blob/master/CONTRIBUTING.md#development

@privatenumber privatenumber closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
@timfish
Copy link
Author

timfish commented May 14, 2024

Do you have any tips for debugging loader hooks? I'm console.loging in multiple modules but it's super painful to not be able to add breakpoints in the node built in code!

@nwalters512
Copy link
Contributor

I'm highly confident that this is an issue with import-in-the-middle and not tsx: getsentry/sentry-javascript#12011 (comment)

@timfish
Copy link
Author

timfish commented May 14, 2024

Turns out it's a Node bug triggered by a combination of import-in-the-middle setting parentURL to node:* and tsx attempting to load missing files while searching through various extensions.

nodejs/node#52987

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants