swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.81k stars 76 forks source link

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

Open Xinkai opened 4 weeks ago

Xinkai commented 4 weeks ago

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