-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Native support for tsconfig's paths resolution #6828
Comments
I have to say, I also would like to have this 🤔 So I would not need this anymore in all my projects |
TSConfig |
My solution: import tsconfig from "./tsconfig.json";
const tsconfigPathAliases = Object.fromEntries(
Object.entries(tsconfig.compilerOptions.paths).map(([key, values]) => {
let value = values[0];
if (key.endsWith("/*")) {
key = key.slice(0, -2);
value = value.slice(0, -2);
}
const nodeModulesPrefix = "node_modules/";
if (value.startsWith(nodeModulesPrefix)) {
value = value.replace(nodeModulesPrefix, "");
} else {
value = path.join(__dirname, value);
}
return [key, value];
})
); Works with my // ...
"paths": {
"@/*": ["src/*"],
"semantic-ui-css": ["node_modules/fomantic-ui-css"],
"mobx-react": ["node_modules/mobx-react-lite"],
"lodash": ["node_modules/lodash-es"],
"markdown-it": ["node_modules/@esm-bundle/markdown-it"]
}
// ... |
The feature should explicitly support (and validate it works with) a tsconfig.json with the |
Adding some notes from #10063: tsconfig paths do not work in vite.config.ts, which was closed in favor of this issue. In addition to the recommended functionality of |
How do you apply this exactly? |
While I'd like to see first-class support for this as well, unfortunately tsconfig paths and
Because of that it's not great to support this ootb and potentially slowing down more projects. |
I am looking forward to this feature, it will be very useful in the development phase, I need to write some plug-ins in the project, I will use the @ symbol in the plug-in development phase, but vite.config.ts does not support it, typescript supports it, vite app supports it. However, the reference code in vite.config.ts is not supported, which is sad |
How about subpath imports like |
@alamhubb and using |
Thanks, I temporarily solved this problem using tsx |
@alamhubb would you mind sharing your configuration with tsx pls? |
tsconfig.json
i use @ in HelloWorldGrammarParser.ts |
Clear and concise description of the problem
By having Typescript integration in Vite, I kind of assumed all tsconfig features would work out-of-the-box. While migrating from Next.js I discovered that Vite is lacking support for
paths
resolving. I noticed that many of my friends did that as well, although I would be in favour of adding a full typescript features support.Suggested solution
Add native support for
paths
resolutions similar to: https://www.npmjs.com/package/vite-tsconfig-pathsAlternative
Document lack of this feature in Typescript section and recommend using: https://www.npmjs.com/package/vite-tsconfig-paths
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: