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

Support eslint-import-resolver-alias Config #249

Open
jhoffmcd opened this issue Nov 29, 2020 · 7 comments
Open

Support eslint-import-resolver-alias Config #249

jhoffmcd opened this issue Nov 29, 2020 · 7 comments

Comments

@jhoffmcd
Copy link

Request to support module aliases as provided by the config in eslint-import-resolver-alias. It seems like the rule node/no-missing-import is not aware of aliases configured by the eslint-import-resolver-alias settings.

Example configuration:

{
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "sourceType": "module"
  },
  "extends": [
    "eslint:recommended",
    "plugin:node/recommended",
    "plugin:jest/recommended",
    "prettier"
  ],
  "plugins": ["prettier"],
  "settings": {
    "import/resolver": {
      "alias": {
        "map": [["~", "./src"]],
        "extensions": [".js", ".json"]
      }
    }
  },
  "rules": {
    "prettier/prettier": "error",
    "node/no-unsupported-features/es-syntax": [
      "error",
      {
        "version": ">=12.10.0",
        "ignores": ["modules"]
      }
    ]
  }
}

Still produces an error with this statement:

import { logger } from "~/utils/logging";

// error  "~/utils/logging" is not found  node/no-missing-import
@jhoffmcd
Copy link
Author

Also filed an issue over at the alias plugin because I am not sure where the change would be needed:

johvin/eslint-import-resolver-alias#20

@Airkro
Copy link

Airkro commented Dec 18, 2020

Turn off rules duplicate with eslint-plugin-import, use eslint-plugin-import directly might be a better solution.

@lamuertepeluda
Copy link

@Airkro what do you mean exactly? Like

"node/no-missing-require": "off", ?

@Airkro
Copy link

Airkro commented Dec 18, 2020

@lamuertepeluda

Yep. install eslint-plugin-import

+ 'import/no-extraneous-dependencies': 'error',
- 'node/no-extraneous-require': 'error',
- 'node/no-extraneous-import': 'error',
+ 'node/no-extraneous-require': 'off',
+ 'node/no-extraneous-import': 'off',

+ 'import/no-unresolved': 'error'
- 'node/no-missing-require': 'error',
- 'node/no-missing-import': 'error',
+ 'node/no-missing-require': 'off',
+ 'node/no-missing-import': 'off',

now you can use eslint-import-resolver-x

@lamuertepeluda
Copy link

@Airkro thank you!! You pointed me in the right direction! 😃 I have a node-express only project.

I did it like this in my root .eslintrc.json file and it's working

{
  "extends": [
    "eslint:recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:node/recommended",
  ],
  "plugins": ["import", "node"],
  "root": true,
  "env": {
    "es6": true,
    "browser": false,
    "node": true,
    "commonjs": true
  },
  "settings": {
    "import/resolver": {
      "alias": {
        "map": [
          ["@src", "./src"],
          ["@api", "./src/api"],
          ["@migrations", "./src/migrations"],
          ["@utils", "./src/utils"],
          // customize as you need
        ],
        "extensions": [".js", ".json", ".node"] // customize as you need
      }
    }
  },
  "rules": {
     // place other rules here
     // This one handles require() resolution respecting aliases IF you set commonjs: true
    "import/no-unresolved": ["error", { "commonjs": true }],
    "import/no-extraneous-dependencies": "error",
    // Turned off because conflicts with the ones above and does not support aliases
    "node/no-missing-require": "off",
    "node/no-extraneous-import":"off",
    // place other rules here
  }
}

and I am using module-alias and eslint-import-resolver-alias in addition to this.

max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 6, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 6, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 6, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 7, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 11, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 13, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 20, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 26, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 27, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
max-nextcloud added a commit to nextcloud/text that referenced this issue Apr 27, 2022
eslint-plugin-import will use webpack resolver and check for missing imports.
The node variant is causing false error reports as it does not use resolvers.

See mysticatea/eslint-plugin-node#249 (comment) for details.

Signed-off-by: Max <[email protected]>
@quantuminformation
Copy link

we get this:

Oops! Something went wrong! :(

ESLint: 8.57.0

EslintPluginImportResolveError: unable to load resolver "alias".
Occurred while linting /Users/nikos/WebstormProjects/agcra-app/app/components/AdminNavTabs.tsx:1
Rule: "import/namespace"
    at requireResolver (/Users/nikos/WebstormProjects/agcra-app/node_modules/.pnpm/[email protected]_@[email protected][email protected]__kttqjlkde72ifr4qchnoh6ko5e/node_modules/eslint-module-utils/resolve.js:199:17)

@scagood
Copy link

scagood commented Mar 9, 2024

We have a supported version of this plugin over at https://github.com/eslint-community/eslint-plugin-n

We do support aliases from both typescript and the package.json.

If you need anymore settings we'd be happy to help!

brettz9 pushed a commit to brettz9/eslint-plugin-node that referenced this issue Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants