typescript-transform-paths icon indicating copy to clipboard operation
typescript-transform-paths copied to clipboard

[Bug] Paths seems to be required but not sure why

Open dborstelmann opened this issue 4 years ago • 5 comments

I don't use paths in my project, just baseUrl like so:

{
  "extends": "../../tsconfig.packages.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist",
    "baseUrl": "./src"
  }
}

I have to add a blank paths to make this work. Is this avoidable?

Doesn't work:

"plugins": [
  { "transform": "typescript-transform-paths", "useRootDirs": true },
  { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
]

Works great:

"paths": {
  "*": ["*"]
},
"plugins": [
  { "transform": "typescript-transform-paths", "useRootDirs": true },
  { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
]

dborstelmann avatar Nov 03 '21 04:11 dborstelmann

Thanks for the report. That shouldn't happen, no. I recently discovered the same. It applies specifically to useRootDirs if paths isn't set.

I have it covered in the upcoming major release, but I will try to get a patch out in the next few days for you!

nonara avatar Nov 03 '21 04:11 nonara

Thanks for the quick response! This lib solved me running js in production tonight so it's much appreciated.

dborstelmann avatar Nov 03 '21 04:11 dborstelmann

Quick update (It's been a busy couple of weeks!)

As memory serves, I ran into some challenges surrounding this same area of code while working on what was supposed to be another small change. All of it is sorted out in the new upcoming major version, which has some significant internal changes.

That in mind, in the mean time, I'd suggest continuing to use the workaround. I'll leave this issue open and update you as soon as the next major comes out! At that point you won't need any workarounds

nonara avatar Nov 14 '21 23:11 nonara

https://github.com/LeDDGroup/typescript-transform-paths/blob/master/src/utils/resolve-path-update-node.ts#L39

It seems that this if statement is suppressing baseUrl resolution, which happens at resolveModuleName, right below.

I'll open a pull request trying to handle this, and then I would like to have some help identifying some other possible corner cases.

fsmaia avatar Aug 09 '22 21:08 fsmaia

any progress ? 😂 @nonara

holynewbie avatar Jan 17 '23 12:01 holynewbie