E
E
Enma2022-03-19 22:07:56
typescript
Enma, 2022-03-19 22:07:56

How to make React + Typescript aliases work in VSCODE?

Used by webpack 5.
my tsconfig

spoiler

{
    "compilerOptions": {
        "target": "es5",
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "allowJs": true,
        "skipLibCheck": true,
        "allowSyntheticDefaultImports": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "module": "esnext",
        "moduleResolution": "node",
        "isolatedModules": true,
        "noEmit": true,
        "jsx": "react-jsx",
        "sourceMap": true,
        "strict": true,
        "esModuleInterop": true,
        "resolveJsonModule": true
    },
    "baseUrl": "src",
    "paths": {
        "@pages": [
            "pages/*"
        ]
    },
    "include": [
        "src"
    ]
}



snippet from webpack config
spoiler

resolve: {
        extensions: ['.js', '.jsx', '.ts', '.tsx'],
        alias: {
            '@pages': path.resolve(__dirname, 'src/pages')
        },
    },



the alias itself works, but in VSCODE it's import is highlighted in red and is not automatically imported, how can I fix this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question