swc-project / swc-project/swc-node

swc-node does not work if npm package ends with ".js"

Open
#865 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The following code does not work. Full minimal reproduce repo: https://github.com/Xinkai/swc-node-minio-reproduce

import { Client } from "minio";

const client = new Client({
    accessKey: "123",
    secretKey: "123",
    endPoint: "example.com",
});
node --import @swc-node/register/esm-register src/main.ts

node:internal/modules/run_main:122
    triggerUncaughtException(
    ^
Error: Cannot resolve 'ipaddr.js' for extension aliases 'ipaddr.ts,ipaddr.tsx,ipaddr.js' in '/home/xinkai/projects/Web/swc-node-minio-reproduce/node_modules/.pnpm/minio@8.0.2/node_modules/minio/node_modules': ipaddr.js cannot be resolved in file:///home/xinkai/projects/Web/swc-node-minio-reproduce/node_modules/.pnpm/minio@8.0.2/node_modules/minio/dist/esm/internal/helper.mjs
    at resolve (file:///home/xinkai/projects/Web/swc-node-minio-reproduce/node_modules/.pnpm/@swc-node+register@1.10.9_@swc+core@1.7.42_@swc+types@0.1.12_typescript@5.6.3/node_modules/@swc-node/register/esm/esm.mjs:157:15)
    at async nextResolve (node:internal/modules/esm/hooks:748:22)
    at async Hooks.resolve (node:internal/modules/esm/hooks:240:24)
    at async handleMessage (node:internal/modules/esm/worker:199:18)

Node.js v22.10.0

I found #817 and #824, but I don't think they fixed this problem.

Node: v22.10
@swc-node/register: 1.10.9

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.

Research direction

Start with the linked minimal reproduction and run the shown Node command using @swc-node/register/esm-register. Inspect the resolver in @swc-node/register/esm/esm.mjs around resolve, especially the extension-alias handling reported near line 157. Done means the reproduction imports minio without the ipaddr.js resolution error.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.