Skip to content

Why are absolute ids skipped? #101

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

Closed
eddiemonge opened this issue Mar 14, 2023 · 7 comments
Closed

Why are absolute ids skipped? #101

eddiemonge opened this issue Mar 14, 2023 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@eddiemonge
Copy link

On this line https://github.com/aleclarson/vite-tsconfig-paths/blob/master/src/index.ts#L114, it skips it if it is an "absolute path" but why?

I have this in my tsconfig: "paths": { "/*": ["./*"] }," so I can do imports like import CardNavItem from '/UI/CardNavItem';. This fails through the plugin but if I remove the isAbsolute check it works and in my limited testing, doesn't seem to break anything else.

@aleclarson aleclarson added the bug Something isn't working label Mar 14, 2023
@aleclarson
Copy link
Owner

It's a perf optimization. PR welcome

@aleclarson aleclarson added the help wanted Extra attention is needed label Mar 14, 2023
@rtmann
Copy link

rtmann commented Oct 17, 2023

Perf optimization? So is this saying that vite-tsconfig-paths does not support absolute alias's like "@common/models" ????

If so, I've wasted days debugging my build and this was the problem the whole time.

@aleclarson
Copy link
Owner

@rtmann This issue is about using tsconfig to redirect paths like /x/y/z (note the leading slash)

@pappnase99
Copy link

Just ran into this issue. Even though absolute paths are generally disencouraged, there are legitimate use cases. For example, if you want to deploy code into AWS Lambda functions, but you want to keep your deployment size as minimal as possible, you can use dependency layers where you can put common code like service classes etc. These layers are then mounted into the Lambda with a prefix '/opt', creating import paths like '/opt/services/MyService', so you know in the target runtime this absolute path will be available to your code.

So making absolute paths possible via config param/whatever would be a big improvement.

@aleclarson
Copy link
Owner

@pappnase99 Can't you just use explicit file extensions? I'm confused how tsconfig.json paths are used in this scenario.

@aleclarson
Copy link
Owner

I've decided to support this use case in v6.

You can give it a try starting with v6.0.0-beta.3:

pnpm add -D vite-tsconfig-paths@next

@pappnase99
Copy link

@pappnase99 Can't you just use explicit file extensions? I'm confused how tsconfig.json paths are used in this scenario.

Not sure if I understand your question, but in my use case it's about mapping an absolute file path to something in your workspace, that's why you have 'paths' entries in tsconfig like this: "/opt/services/*": ["./src/services/*"],. As explained, in the target runtime env the stuff will be deployed into the '/opt' path, but it's not there in compilation time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants