-
-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Describe the bug
Configuring Vite with a path alias (and TypeScript) causes it to create an invalid relative path.
For instance, setting this in vite.config.ts
resolve: {
alias: [
{
find: "@test/ui",
replacement: path.resolve(import.meta.dirname, "./src"),
},
],
},
And this in tsconfig.json
:
"paths": {
"@test/ui/*": ["src/*"]
},
Then importing import { graphql } from '@test/ui/gql';
causes it to throw errors like:
Failed to resolve import "./../../../../../src/gql/graphql" from "src/App.tsx". Does the file exist?
If it must internally transform it to a relative import, it should become ./gql/graphql
in this case since App.tsx
is in the src
directory.
I created a CodeSandbox but it ends up working there while doing the equivalent locally on Windows does not.
https://codesandbox.io/p/devbox/swc-graphql-plugin-path-alias-issue-repro-2v6j8d
If I switch it to use a relative import, it works.
Expected behavior
It should work on Windows like it does on other platforms
Additional context
If I had to guess the cause, it would be that it doesn't handle Windows paths like C:\\workspace\project
correctly.