-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug?] Index file import not being transformed correctly #159
Comments
Hi @SammyWhamy . Thanks for the report! Sorry to hear you're facing issues with the library. This could simply be an issue with rootDir or something to that effect. Though it looks like it might have to do with a known issue in handling indexes. I have this mostly fixed in the new version, but I have to complete it. If you can provide a reproduction, I will have a look! |
Closing for housekeeping. Feel free to reopen if you have a reproduction. |
Came back to this after a while, with a reproduction! I have the following typescript file: {
"compilerOptions": {
"lib": [
"es2021",
],
"module": "esnext",
"target": "es2021",
"moduleResolution": "Node",
"sourceMap": true,
"declaration": true,
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",
"rootDir": "./src",
"outDir": "./dist",
"plugins": [
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true}
],
"paths": {
"@client": ["client/index.js"],
"@objects": ["objects/index.js"],
"@cache": ["cache/index.js"],
"@utils": ["utils/index.js"],
}
}
} In my typescript files, I want to use imports in the following way: import { Client, SomeOtherClass } from "@client"; Where export * from './Client.js'; And export class Client { }
export class SomeOtherClass { } However, when building this source, the import gets wrongly transformed to import { Client, SomeOtherClass } from "./client"; Which in my experience doesn't work with node, as you need to explicitly provide the |
This is tied to a know issue with indexes #136. Hoping to have that sorted in the next major version. For now, you can use the @transform-path tag to explicitly set the output to |
I have this settings in my tsconfig:
But when I
import { } from "@util";
It emits this code:
import { } from "../util";
If I instead rename the file to something else, e.g.
barrel
, it emits this:import { } from "../util/barrel";
The problem is, node can resolve neither of these. And as I specify that
@util
should be rewritten toutil/index.js
I expect it to keep theindex.js
part, without this my import simply doesn't function.I can't really tell if this is intended behavior or not, but I think emitting the full path (including
index.js
) should always be a safe option if it is specified as such in thepaths
option.I know I could instead do
"@util/*": ["util/*"]
And then
import { } from "@util/index.js";
But it'd be even better if I can have it emit the
index.js
for me as well.The text was updated successfully, but these errors were encountered: