swc-project / swc-project/swc-node

swc-node/register make follow-on `--import` resolve to wrong path

Open
#846 3 comments 0 reactions 1 assignee View on GitHub

@Brooooooklyn is already working on this.

Since Sep 4, 2024.

Dominant language
TypeScript
Stars
2k
Forks
95
Avg merge
14d 11h
Merged PRs (30d)
1

Description

Assume I have test.js, I can run node --import ./test1.js well.

But node --import @swc-node/register/esm-register --import ./test1.js fail:

node:internal/modules/run_main:129
    triggerUncaughtException(
    ^
Error: All of the aliased extensions are not found for /hax/test1.js: ./test1.js cannot be resolved in file:///hax/x/
    at resolve (file:///hax/x/node_modules/@swc-node/register/esm/esm.mjs:157:15)
    at async nextResolve (node:internal/modules/esm/hooks:866:22)
    at async Hooks.resolve (node:internal/modules/esm/hooks:304:24)
    at async MessagePort.handleMessage (node:internal/modules/esm/worker:196:18)

Node.js v20.16.0

I notice the dir seems become parent dir, and found that node --import @swc-node/register/esm-register/esm-register --import ./x/test1.js works.

Note, version 1.10.0 is ok (though not support --import ./test.ts). It seems become broken from 1.10.1 .

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.