build error TS2304: Cannot find name XXX
See original GitHub issueenvironment: Node: v16.14.0 Vite: v2.19.12 - v3.0.0 Vue: v3.2.37 Typescript: v4.7.4 i use unplugin-auto-import, then run ‘yarn run build’ get error message:
src/views/home/index.vue:12:15 - error TS2304: Cannot find name 'useMainStore'.
src/layouts/admin_layout.vue:10:19 - error TS2304: Cannot find name 'storeToRefs'.
code:
import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: true
},
plugins: [
vue(),
AutoImport({
imports: [
{
vue: ['ref', 'onMounted', 'computed'],
pinia: ['storeToRefs', 'mapActions'],
'@/stores/mainStore': ['useMainStore']
}
],
dirs: ['src/hooks'],
eslintrc: {
enabled: true,
filepath: './.eslintrc-auto-import.json',
globalsPropValue: 'readonly'
},
dts: 'types/auto-imports.d.ts'
}),
Components({
dirs: ['src/components', 'src/layouts'],
directoryAsNamespace: true,
dts: 'types/components.d.ts'
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "@/styles/index.scss";'
}
}
}
})
tsconfig.json
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["types/*", "src/**/*", "src/**/*.vue"],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"references": [
{
"path": "./tsconfig.config.json"
}
]
}
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
TS2304: Cannot find name xxx but no errors with tsc #334
Expected behavior: Complete successfully without any errors like running npm run tsc does Actual behavior: Error messages logged includes: ...
Read more >ng2-material: error TS2304: Cannot find name 'process'
After updating my project to Justin DuJardin's ng2-material version 0.3.8 (based on Angular 2.0.0-beta.14 ), it fails to compile with the ...
Read more >Fix the Cannot Find Name 'require' Error in TypeScript
To fix the “cannot find name 'require'” error in TypeScript, install the @types/node package into your project by running npm i -D @types/node...
Read more >error ts2307: cannot find module or its corresponding type ...
I am having SOMETIMES an issue message when I run the command "npm run build:xxx" happens randomly.. ERROR in src/app/framework/services/svg2image/svg-to-image.
Read more >Jasmine - Cannot find name describe (or beforeEach, expect ...
After upgrading from Angular 2 to Angular 4, there were some delightful new errors in my unit tests ... TS2304: Cannot find name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
src/views/home/index.vue:12:15 do you want to use them in
<template>
?if so, add config
vueTemplate: true
@asdjgfr Thanks, i found that i run
pnpm build-only
first and then runpnpm build
, it can works.