dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

Fix missing paths when using typescript's module nodenext feature #216

Closed IgnusG closed 1 year ago

IgnusG commented 2 years ago

This resolution requires relative/mapped import paths to end with .js This PR detects if a path ends with .js and if so adds more extension type paths to try, that omit this extension when attaching additional extensions to match the actual existing files.

Reference https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#esm-nodejs

Should resolve https://github.com/dividab/tsconfig-paths/pull/213 (edit 1: wrong issue sorry, edit 2: actually I believe this might resolve that issue as well) & https://github.com/aleclarson/vite-tsconfig-paths/issues/59

WoodyWoodsta commented 1 year ago

Is this going anywhere?

aleclarson commented 1 year ago

Can you copy over the test from https://github.com/dividab/tsconfig-paths/pull/213 ?

WoodyWoodsta commented 1 year ago

I would also like to know if this handles .mjs files, which is what is emitted by the TS compiler when files are .mts files.

aleclarson commented 1 year ago

I would also like to know if this handles .mjs files, which is what is emitted by the TS compiler when files are .mts files.

Good catch. There should definitely be a test for that.

IgnusG commented 1 year ago

I'll add both tests and check the mjs support 👍

IgnusG commented 1 year ago

I would also like to know if this handles .mjs files, which is what is emitted by the TS compiler when files are .mts files.

@WoodyWoodsta can you please check if https://github.com/dividab/tsconfig-paths/pull/216/commits/39354fbbb6c819caf53ff1459510b4c6ca1cf699 works for you? I barely remember this PR so I just quickly wrote down a test for it

IgnusG commented 1 year ago

@jonaskello could you please take a look through this when you have the time?

IgnusG commented 1 year ago

For anyone wanting to use this in the meantime with yarn add this resolution to your package.json

{
  "resolutions": {
    "tsconfig-paths": "github:ignusg/tsconfig-paths@dev"
  }
}
datner commented 1 year ago

Hey, this pr was thoroughly tests, reviewed, and even approved! This is great work and an important step in moving to full esm.

Is there a reason why this isn't merged?

jonaskello commented 1 year ago

Yes, seems like this change has enough tests so let's merge it.