Closed alanszp closed 6 months ago
Debugging I found the problem!
I just renamed the file from src/passport.ts
to src/passportInstance.ts
and it stopped!
@izumiya @mgcrea @nicholas-ochoa @Jokero I'm closing this since I found the problem, but I would suggest trying to reproduce it, since it's a bug.
It seems that when you import a lib in a file with the same name as the lib (and maybe on the root of the project) it tries to add the ./
I think this should be reopened, as it seems to be an actual bug in tsc-alias
.
I have encountered this while working on a backend typescript project. My theory is that if a module is defined in a file with the same name as a node_modules dependency, and such module imports the node_modules dependency, the import is wrongly interpreted as to be relative (basically importing itself).
I have this code in a file scr/utils/zod.ts
, which contains utility functions related to the Zod validation library.
// scr/utils/zod.ts
// defines extra helpers and utility functions for the zod library
import { z } from 'zod' // import the library
export function arrayWithOnlyValidElements<T extends z.ZodTypeAny>(
itemSchema: T,
) {
const catchValue = {} as never;
return z
.array(itemSchema.catch(catchValue))
.transform((arr) => arr.filter((el) => el !== catchValue))
.catch([]);
}
After running tsc
(with ES imports), the import is still correctly import { z } from 'zod.js'
.
After running tsc-alias
, a .js
is added to the import:
> head -n 1 dist/utils/zod.js
import { z } from 'zod.js'
Which is incorrect. This is with tsc-alias 1.8.7
.
@justkey007 is it possible to reopen this issue?
Having local modules with the same name as some dependency, in a subdir like utils
or helpers
, is quite a common pattern when writing code that is related to that dependency.
Context
package.json
yarn.lock
Original TS file
JS code (Compiled by TSC)
tsc-alias output
Expectations
tsconfig.json
More context
It's strange since I have other libs and default imports but it's only happening in passport import!