Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript: Unable to resolve path for absolute pathes #125

Open
JonasDoe opened this issue Aug 13, 2024 · 2 comments
Open

Typescript: Unable to resolve path for absolute pathes #125

JonasDoe opened this issue Aug 13, 2024 · 2 comments
Labels
question Further information is requested

Comments

@JonasDoe
Copy link

JonasDoe commented Aug 13, 2024

I'm facing the problem that my absolute imports, e.g. ./myDir will result in errors like Unable to resolve path to module './myDir'. I figure that's b/c the setting moduleDirectory doesn't exist here. Before, with eslint-plugin-import, my settings looked like similar to that:

...
const _import  = require( "eslint-plugin-import-x")
...
module.exports = [{
    settings: {
        "_import/resolver": {
            node: {
                extensions: [".js", ".jsx", ".ts", ".tsx"],
                moduleDirectory: ["node_modules", "./src"],
            },
        },
    }
]}

moduleDirectory doesn't exist in the TypeScript settings you've defined:

{
    typescript: {
        settings: {
            'import-x/extensions': readonly [".ts", ".tsx", ".js", ".jsx"];
            'import-x/external-module-folders': string[];
            'import-x/parsers': {
                '@typescript-eslint/parser': (".ts" | ".tsx" | ".cts" | ".mts")[];
            };
            'import-x/resolver': {
                node: {
                    extensions: readonly [".ts", ".tsx", ".js", ".jsx"];
                };
            };
        };
        ...
    };
};

I apologize If I'm missing something or this behavior isn't related to your plugin - that's just my best guess. I'm in the middle to migrate to eslint 9 and seem to have to adjust lots of things by myself, so it's possible I messing up something else. I think the original solution came back then from https://stackoverflow.com/a/70741539/5767484.

@JounQin
Copy link
Member

JounQin commented Aug 13, 2024

  1. The settings prefix is hard coded as import-x/ even with flat config
  2. If you're using TypeScript, you'd better to use https://github.com/import-js/eslint-import-resolver-typescript

@JounQin JounQin added the question Further information is requested label Aug 13, 2024
@JonasDoe
Copy link
Author

JonasDoe commented Aug 13, 2024

Oh, thank you for the fast reply! I presumed it must be _import resp. my import alias because this is what I had to use another places in the config, e.g. for rules: ["_import/no-unresolved": "error"]. Idk whether this is intended or unavoidable since I'm lacking a deeper understanding on how the config file gets used, though - I'm just probing to get things running again.

Thank you also for suggesting this alternative - I'll give it a try if I face more import-related problems! But I love the import sorting of this plugin. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants