question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

build error TS2304: Cannot find name XXX

See original GitHub issue

environment: 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
azaletacommented, Jul 17, 2022

src/views/home/index.vue:12:15 do you want to use them in <template> ?

if so, add config vueTemplate: true

0reactions
nyrfcommented, Oct 22, 2022

@asdjgfr Thanks, i found that i run pnpm build-only first and then run pnpm build, it can works.

  "scripts": {
    "dev": "vite",
    "build": "run-p type-check build-only",
    "preview": "vite preview --port 4173",
    "build-only": "vite build",
    "type-check": "vue-tsc --noEmit",
    "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
  },
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found