bloomberg / ts-blank-space

A small, fast, pure JavaScript type-stripper that uses the official TypeScript parser.
https://bloomberg.github.io/ts-blank-space
Apache License 2.0
544 stars 8 forks source link

Module Loader fails with `--experimental-import-meta-resolve` #11

Closed KnisterPeter closed 1 month ago

KnisterPeter commented 1 month ago

Describe the bug In a runtime environment with --experimental-import-meta-resolve enabled, the module loader fails and does not resolve correctly.

To Reproduce Steps to reproduce the behavior:

  1. Create a program which uses import.meta.resolve to resolve a module.
  2. Start the programm with node --experimental-import-meta-resolve --import ts-blank-space/register ./path/to/program.ts.

The program/loader fails with the following error:

> node --import ts-blank-space/register  --experimental-import-meta-resolve ./src/index.ts "./src/index.ts"

node:internal/modules/run_main:123
    triggerUncaughtException(
    ^
TypeError [Error]: Invalid URL
    at Object.getPackageScopeConfig (node:internal/modules/package_json_reader:132:33)
    at packageResolve (node:internal/modules/esm/resolve:792:43)
    at moduleResolve (node:internal/modules/esm/resolve:908:18)
    at defaultResolve (node:internal/modules/esm/resolve:1038:11)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at resolve (file:///xxx/node_modules/.pnpm/ts-blank-space@0.4.1/node_modules/ts-blank-space/loader/hooks.js:7:22)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:199:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:816:20) {
  code: 'ERR_INVALID_URL',
  input: 'input.ts'
}

Node.js v22.8.0

Expected behavior It should be able to resolve the required module.

Environment (please complete the following information):

KnisterPeter commented 1 month ago

Without --experimental-import-meta-resolve it does work, but not resolves relative to the parent. That is expected and not an issue with the loader.

KnisterPeter commented 1 month ago

I guess it's me holding it wrong. 😄