VSCode auto import not recognising eslint alias/webpack resolve/tsconfig paths
Asked Answered
S

0

7

I have an node module which I want to create an alias for.

I have the following configs:

// tsconfig.json
{
    "compilerOptions": {
        ...
        "allowJs": true,
        "module": "commonjs",
        "target": "es6",
        "jsx": "react",
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "baseUrl": "./",
        "moduleResolution": "node",
        "paths": {
            "@my-lib/*": [
                "node_modules/my-lib/src/Components/*"
            ]
        }
    },
    "exclude": ["node_modules"]
}


// webpack.config.js
resolve: {
        extensions: ['.js', '.jsx', '.tsx', '.ts'],
        alias: {
            '@my-lib': path.resolve(
                './node_modules/my-lib/src/Components'
            ),
        }
    },

// eslintrc.json
"settings": {
        "import/parsers": {
            "@typescript-eslint/parser": [".ts", ".tsx"]
        },
        "import/resolver": {
            "typescript": {},
            "alias": {
                "map": [
                    [
                        "@my-lib",
                        "./node_modules/my-lib/src/Components"
                    ]
                ],
                "extensions": [".js", ".jsx", ".ts", ".tsx"]
            }
        }

But when importing a module from my-lib vscode auto import resolves it to: my-lib/src/Components/...

Another config I have is: "typescript.preferences.importModuleSpecifier": "relative", (though I've tried auto and non-relative as well)

I tried pretty much every combination of baseUrl and paths.
Appreciate any help!

Stretch answered 21/2, 2020 at 11:32 Comment(1)
Hey, I know this question's 9 months old, but did you solve this in the end? I'm having the same issueLabanna

© 2022 - 2024 — McMap. All rights reserved.