首页 > 其他分享 >解决Cannot find module ‘@/score/test/index.vue‘ or its corresponding type declarations.的报错

解决Cannot find module ‘@/score/test/index.vue‘ or its corresponding type declarations.的报错

时间:2024-08-20 23:51:07浏览次数:10  
标签:index vue src ts json 报错 esnext true tsconfig

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noImplicitThis": true,
    "baseUrl": ".",
    "types": ["webpack-env"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "src/**/*.d.ts",
    "src",
    "src/typings/*.d.ts"
  ],
  "exclude": ["node_modules"]
}

注意还应安装@types/webpack-env

npm install --save-dev @types/webpack-env

检查tsconfig.json文件,注意tsconfig.json不要与tsconfig.app.json冲突,可以将其合并为上文的代码,也可以分开为两个

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noImplicitThis": true,
    "baseUrl": ".",
    "types": ["webpack-env"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/*.d.ts", "src/typings/*.d.ts"],
  "exclude": ["node_modules"]
}

tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

标签:index,vue,src,ts,json,报错,esnext,true,tsconfig
From: https://blog.csdn.net/m0_73067198/article/details/141308192

相关文章