VS Code does not autocomplete or follow a Vite alias like @/
import from '@/components/Button' builds fine but is not resolved in the editorShort answer
Vite and VS Code read different files. Vite reads resolve.alias in the Vite config. VS Code reads paths from jsconfig.json (or tsconfig.json), so both must name the same alias. Put the jsconfig at the project root, and make sure its include covers the files you edit.
Fix it fast
1Find out which cause you have
Check that both files declare the same alias and where the jsconfig sits relative to the code.
ls jsconfig.json tsconfig.json vite.config.* grep -n "alias\|paths" jsconfig.json vite.config.*2Match what you see, then jump to its fix
- 1
No jsconfig.json or tsconfig.json in the projectThe alias exists only in vite.configFix - 2
A jsconfig exists but only some folders get IntelliSenseThe jsconfig is in the wrong folder or include skips the filesFix - 3
The editor resolves one prefix but Vite resolves another, or the build fails while the editor is happyAlias in Vite and paths in jsconfig disagreeFix
- 1
What does the error look like?
import from '@/components/Button' builds fine but is not resolved in the editorNo autocomplete or go to definition on aliased importsAliased paths show as unresolved while the app runs
Cause 1 of 3
The alias exists only in vite.config
1Check
Vite's resolve.alias is for the bundler. The editor needs paths in jsconfig.json, which is relative to baseUrl as the VS Code docs say.
ls jsconfig.json2Fix
Create jsconfig.json at the root of the JavaScript code with the same mapping as the Vite alias.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"]
}3Verify
Reload the VS Code window and press Ctrl or Cmd with a click on an aliased import.
# Command Palette: Developer: Reload WindowConfirmed by code.visualstudio.com
Cause 2 of 3
The jsconfig is in the wrong folder or include skips the files
1Check
A jsconfig.json marks the root of a JavaScript project. Its include and exclude paths are relative to the file, and include defaults to everything in its folder.
git ls-files | grep jsconfig
grep -n "include\|exclude" jsconfig.json2Fix
Move the file to the project root, or widen include. Exclude build output and node_modules so suggestions do not appear twice.
{
"compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./src/*"] } },
"include": ["src", "vite.config.js"],
"exclude": ["node_modules", "dist"]
}3Verify
Open a file in each folder and check that aliased imports resolve.
# Command Palette: TypeScript: Restart TS ServerConfirmed by code.visualstudio.com
Cause 3 of 3
Alias in Vite and paths in jsconfig disagree
1Check
Vite wants an absolute path in resolve.alias; a relative value is used as written. The jsconfig side stays relative to baseUrl, so write each in its own form and compare the target folder.
grep -n -A4 "alias" vite.config.*2Fix
Set the Vite alias with an absolute path and keep the jsconfig target pointing at the same folder.
import { fileURLToPath, URL } from 'node:url'
export default {
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
},
}3Verify
Run a build and check that the editor shows no unresolved import.
npx vite buildConfirmed by vite.dev
How do I stop it coming back?
- Change the alias in vite.config and jsconfig.json in the same commit.
- Keep one jsconfig per project root; use more only for separate projects in a monorepo.
- Reload the window after editing jsconfig.json.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fixWeb apps
A POST to a Google Apps Script web app returns 405 or a CORS error
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.
3 causes, each with a fix