privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.45k stars 144 forks source link

directory import fails again since 4.15.8 #607

Closed TonyRL closed 3 months ago

TonyRL commented 3 months ago

Acknowledgements

Minimal reproduction URL

https://github.com/TonyRL/tsx-4.15.8-repro

Problem & expected behavior (under 200 words)

Similar to #579 and #583, but with "type": "module".

node:internal/modules/run_main:115 triggerUncaughtException( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@/hello' imported from /workspace/tsx-repro/index.ts at packageResolve (node:internal/modules/esm/resolve:841:9) at moduleResolve (node:internal/modules/esm/resolve:914:18) at defaultResolve (node:internal/modules/esm/resolve:1119:11) at nextResolve (node:internal/modules/esm/hooks:791:28) at resolveBase (file:///workspace/tsx-repro/node_modules/.pnpm/tsx@4.16.0/node_modules/tsx/dist/esm/index.mjs?1719848400741:2:3233) at async resolveDirectory (file:///workspace/tsx-repro/node_modules/.pnpm/tsx@4.16.0/node_modules/tsx/dist/esm/index.mjs?1719848400741:2:3519) at async resolve (file:///workspace/tsx-repro/node_modules/.pnpm/tsx@4.16.0/node_modules/tsx/dist/esm/index.mjs?1719848400741:2:4036) at async nextResolve (node:internal/modules/esm/hooks:791:22) at async Hooks.resolve (node:internal/modules/esm/hooks:238:24) at async handleMessage (node:internal/modules/esm/worker:255:18) { code: 'ERR_MODULE_NOT_FOUND' }

Node.js v22.2.0


- What I expected (in 4.15.7)
```sh
$ pnpm run start
> tsx-repro@1.0.0 start /workspace/tsx-repro
> tsx index.ts

Hello, world!

Bugs are expected to be fixed by those affected by it

Compensating engineering work will speed up resolution and support the project

shinebayar-g commented 3 months ago

Yup tsx is broken since 4.15.8 with the same error.

node:internal/process/promises:391
    triggerUncaughtException(err, true /* fromPromise */);
    ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@/imports' imported from src/main.ts
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at nextResolve (node:internal/modules/esm/hooks:866:28)
    at resolveBase (file://src/node_modules/tsx/dist/esm/index.mjs?1719872235791:2:3233)
    at async resolveDirectory (file://src/node_modules/tsx/dist/esm/index.mjs?1719872235791:2:3519)
    at async resolve (file://src/node_modules/tsx/dist/esm/index.mjs?1719872235791:2:4036)
    at async nextResolve (node:internal/modules/esm/hooks:866:22)
    at async Hooks.resolve (node:internal/modules/esm/hooks:304:24)
    at async handleMessage (node:internal/modules/esm/worker:196:18) {
  code: 'ERR_MODULE_NOT_FOUND'
}

my tsconfig

{
  "compilerOptions": {
    "target": "ES2022",
    "lib": [
      "ES2022"
    ],
    "module": "ES2022",
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "noEmit": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "strict": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "skipLibCheck": true,
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}
rohit-ks commented 3 months ago

+1

Infinitay commented 3 months ago

I thought I was the only one having this issue. I made a repo too with the problem that I'm having: https://github.com/Infinitay/path-alias-issue

Although the odd thing is that if I import a type, it works fine - the issue is when I import an enum and reference/access it.

privatenumber commented 3 months ago

As per the Contribution Guide, please refrain from "me too" comments.

I haven't taken a look at this yet, but if anyone is interested in contributing constructively, feel free to open a PR.

privatenumber commented 3 months ago

This issue is now resolved in v4.16.1.

If you're able to, your sponsorship would be very much appreciated.