Tim Fish
Tim Fish
Hi @nishant-compro, Did you try the patch? If the patch doesn't work, this could be a different issue.
The full stack trace is: ``` TypeError [ERR_INVALID_URL_SCHEME]: 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...
Looking at the stack trace, although `import-in-the-middle` is at the bottom, further up we see frames from `tsx`: ``` at y (file:///Users/tim/Documents/Repositories/sentry-v8-tsx-error-repro/node_modules/tsx/dist/esm/index.mjs?1715684968701:2:2079) at j (file:///Users/tim/Documents/Repositories/sentry-v8-tsx-error-repro/node_modules/tsx/dist/esm/index.mjs?1715684968701:2:3198) ``` I guess it's not...
Tracing the resolving of the otel hooking, it looks like `?iitm=true` is used so that iitm knows that the resolving is actually coming from its hook rather than the original...
> Changing that to just url: url.url makes your reproduction complete without error (though I have no idea what effect that has on import-in-the-middle actually working). Ah, I just re-read...
You're right, but `fileURLToPath('node:util')` also throws with the same error! I think the issue **isn't** the query string, it's more that `import-in-the-middle` results in the `parentURL` being the node built-in...
For example, when the minimal reproduction is run through plain old Node: ```ts import { register } from "node:module"; register("import-in-the-middle/hook.mjs", import.meta.url); await import("node:util"); ``` The iitm resolve function with this...
What I don't yet fully understand is why iitm works with Node as it's using the same `parentURL`s. For example these are the logs from `resolve` in `import-in-the-middle` calling down...
Ah got it, the error is being thrown from here. It's throwing while it's trying to create the error message: https://github.com/nodejs/node/blob/87b87a8f6017545e2c9d6048d7b081f73c8a1072/lib/internal/modules/esm/resolve.js#L265
Node tries to check if the `parentURL` is valid [here](https://github.com/nodejs/node/blob/87b87a8f6017545e2c9d6048d7b081f73c8a1072/lib/internal/modules/esm/resolve.js#L1057), but it doesn't guard against `node:*` URLs and later just throws it into `fileURLToPath` to create the error message. If...