TypeScript cannot see useRoute in a Nuxt project
Fix it fast
Most common cause, 1 of 3The .nuxt type files were never generated
Generate the types and reload the editor window so its language service picks up the new files.
npx nuxt prepare
npx nuxt typecheckShort answer
Cannot find name 'useRoute' in Nuxt means TypeScript does not see the declarations Nuxt writes into .nuxt for its auto-imports. Run npx nuxt prepare to generate them, keep the root tsconfig.json pointing at the .nuxt configs, and if auto-imports are switched off, import useRoute from '#imports'. Applies to Nuxt 4.6, and to Nuxt 3.21 with its single .nuxt/tsconfig.json.
Which cause do you have?
Check three things at once: whether .nuxt holds generated tsconfig files, what the root tsconfig.json contains, and whether nuxt.config turns auto-imports off. Missing .nuxt files point to cause 1, a root tsconfig without .nuxt references to cause 2, an imports block to cause 3.
ls .nuxt/tsconfig*.json
cat tsconfig.json
grep -n -A3 "imports:" nuxt.config.tsThen find the line you see in this list and open its fix:
- 1The .nuxt type files were never generated
ls finds no .nuxt/tsconfig*.json, for example in a fresh clone or a CI job that type-checks before any build - 2The root tsconfig.json no longer points at the generated configs
The .nuxt/tsconfig files exist, but tsconfig.json at the project root has its own compilerOptions and no references or extends entry for .nuxt - 3Auto-imports are turned off in nuxt.config
nuxt.config.ts has imports: { autoImport: false }, and other composables such as ref or useFetch fail in the same way
What does the error look like?
Cannot find name 'useRoute'.Cannot find module '#imports' or its corresponding type declarations.npx nuxt typecheck fails on useRoute, useFetch or ref in every .vue file
Cause 1 of 3
The .nuxt type files were never generated
You seels finds no .nuxt/tsconfig*.json, for example in a fresh clone or a CI job that type-checks before any build
Check
TypeScript cannot find useRoute in Nuxt until the auto-import declarations exist. Nuxt stores those generated types in the .nuxt directory and only writes them when the dev server or a build runs, or when you run nuxt prepare. A checkout that has never run any of these has nothing to read.
ls -la .nuxt 2>/dev/null || echo "no .nuxt directory"Fix
Generate the types and reload the editor window so its language service picks up the new files. In CI, run the same command before nuxt typecheck.
npx nuxt prepare
npx nuxt typecheckVerify
nuxt typecheck finishes without TS2304, and the editor shows the type of useRoute() on hover.
npx nuxt typecheckConfirmed by nuxt.com
Cause 2 of 3
The root tsconfig.json no longer points at the generated configs
You seeThe .nuxt/tsconfig files exist, but tsconfig.json at the project root has its own compilerOptions and no references or extends entry for .nuxt
Check
The generated files only help if the root tsconfig.json loads them. A file replaced by a generic Vue or Vite template, or one with a hand-written paths block, hides the auto-import declarations and the aliases such as #imports. The Nuxt docs advise against editing this file and point to nuxt.config.ts for changes.
grep -n -E "references|extends|paths" tsconfig.jsonFix
Put back the root tsconfig.json from the Nuxt docs for your major version, and move any custom aliases into the alias option of nuxt.config so Nuxt adds them to the generated config.
// Nuxt 4: tsconfig.json
{
"files": [],
"references": [
{ "path": "./.nuxt/tsconfig.app.json" },
{ "path": "./.nuxt/tsconfig.server.json" },
{ "path": "./.nuxt/tsconfig.shared.json" },
{ "path": "./.nuxt/tsconfig.node.json" }
]
}
// Nuxt 3: tsconfig.json
{ "extends": "./.nuxt/tsconfig.json" }Verify
After npx nuxt prepare and an editor reload, useRoute resolves in components and #imports resolves in plain .ts files.
npx nuxt prepare && npx nuxt typecheckConfirmed by nuxt.com
Cause 3 of 3
Auto-imports are turned off in nuxt.config
You seenuxt.config.ts has imports: { autoImport: false }, and other composables such as ref or useFetch fail in the same way
Check
With imports.autoImport set to false, Nuxt stops auto-importing composables and utilities, useRoute included, so each file must import what it uses. The scan: false option is narrower and only stops auto-imports of your own composables, not the framework ones.
grep -n -E "autoImport|scan" nuxt.config.tsFix
Import useRoute explicitly from #imports, which Nuxt keeps available even with auto-imports off, or remove the autoImport line. Prefer #imports over vue-router: Nuxt's useRoute wraps the vue-router one and updates the route only after the new page content has rendered.
<script setup lang="ts">
import { useRoute } from '#imports'
const route = useRoute()
</script>Verify
The page shows route.params values and nuxt typecheck no longer reports the name.
npx nuxt typecheckConfirmed by nuxt.com
How do I stop it coming back?
- Add nuxt prepare as the first step of every CI job that runs nuxt typecheck or vue-tsc.
- Keep tsconfig.json exactly as the Nuxt docs show it and put compiler changes under typescript in nuxt.config.ts.
- If a team turns auto-imports off, add a lint rule or code review note that every composable comes from #imports.
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.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.