VSCode项目jsconfig.json配置失效原因

3,602 阅读1分钟
// jsconfig.json
{  "compilerOptions": {    "baseUrl": "./",    "paths": {      // "~/*": ["./src/*"],      "@/*": ["./src/*"]    }  }}

项目中的jsconfig.json文件配置用vscode打开失效,paths配置的@跳转路径映射无法生效,经过百度和各种尝试发现,因为项目中使用了ts,存在tsconfig.json,需要在tsconfig.json中增加一个配置

// tsconfig.json
{  "compilerOptions": {    "target": "esnext",    "module": "esnext",    "moduleResolution": "node",    "importHelpers": true,    "noImplicitAny": false,    "jsx": "react",    "esModuleInterop": true,    "sourceMap": true,    "baseUrl": "./",    "strict": false,    "paths": {      "@/*": ["src/*"],      "umi/locale": ["./node_modules/umi-plugins-locale"]    },    "allowSyntheticDefaultImports": true,    "allowJs": true    // "experimentalDecorators": true,  },  "include": ["mock/**/*", "src/**/*", "config/**/*", ".umirc.ts", "typings.d.ts"]}

就是"allowJs": true,这样在js和ts文件中的import PaginationComp from '@/pages/ProductManagement/components/PaginationComp';这样可以使用ctrl键进行跳转,右键的Go To Definition也可以生效