vue-tsc icon indicating copy to clipboard operation
vue-tsc copied to clipboard

Use ‘vue-tsc --noEmit’ in ‘lint-staged’ to verify the reference of the alias path @/ prompt an error

Open long-hai-yang opened this issue 5 years ago • 1 comments

Use ‘vue-tsc --noEmit’ in ‘lint-staged’ to verify the reference of the alias path ‘@/’ prompt an error。在package.json中的设置:

"gitHooks": {
   "pre-commit": "lint-staged"
 },
"lint-staged": {
   "src/**/*.{ts,vue}": [
       "vue-tsc --noEmit",
       "git add"
    ]
 }

git commit error message :

× vue-tsc --noEmit:
src/pages/selectCommunity/selectCommunity.vue(41,44): error TS2307: Cannot find module '@/api/community-api' or its corresponding type declarations.

pre-commit hook failed (add --no-verify to bypass)

But,Run vue-tsc --noEmit alone without error, alias ‘@/’ path can pass the validation.

tsconfig.json alias path configuration:

    "baseUrl": ".",
    "paths": {
      "@/components/*": ["./src/components/*"],
      "@/utils/*": ["./src/utils/*"],
      "@/assets/*": ["./src/assets/*"],
      "@/api/*": ["./src/api/*"],
      "@/router/*": ["./src/router/*"],
      "@/pages/*": ["./src/pages/*"],
    }

long-hai-yang avatar Sep 28 '21 03:09 long-hai-yang

I guess lint-staged pick a different tsconfig / jsconfig but I can't confirm, please provide a repro case.

johnsoncodehk avatar Sep 28 '21 10:09 johnsoncodehk