Skip to content

[BUG] import/no-unresolved error despite correct 'declare module' and TypeScript resolution #224

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

Closed
tzachbon opened this issue Apr 10, 2023 · 5 comments

Comments

@tzachbon
Copy link

tzachbon commented Apr 10, 2023

I'm encountering errors related to resolving the path of a custom request.

my-project/src/routes/Projects/Projects.tsx
  20:46  error  Unable to resolve path to module 'accProjectList/ProductLinks'        import/no-unresolved
  22:16  error  Unable to resolve path to module 'accProjectList/ProvidersContainer'  import/no-unresolved

The TypeScript compiler can resolve these paths without any issues, thanks to the correct declare module statement in a d.ts file:

declare module 'accProjectList/*';

Despite the declared module statement, Eslint still throws import/no-unresolved errors for the accProjectList/* modules.

Expected Behavior

The plugin should recognize the declared module statement and be able to resolve the paths to the accProjectList/* modules without any errors, just as TypeScript does.

Additional Information

Eslint version: v8.36.0
eslint-import-resolver-typescript version: 3.5.5
TypeScript version: Version 5.0.2
Node.js version: v18.14.0
Operating System: arm64

.eslintrc:

{
  "root": true,

  "plugins": [
    "import",
    "jest",
    "json",
    "json-files",
    "react",
    "react-hooks",
    "no-unsanitized",
    "promise",
    "spellcheck"
  ],

  "parser": "@babel/eslint-parser",

  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "requireConfigFile": false
  },

  "settings": {
    "react": {
      "version": "detect"
    }
  },

  "overrides": [
    {
      "files": ["*.{js,ts,tsx}"],

      "settings": {
        "import/parsers": {
          "@typescript-eslint/parser": [".ts", ".tsx"]
        },
        "import/resolver": {
          "node": {
            "extensions": [".js"]
          },
          "typescript": {}
        }
      }
    },
    {
      "files": ["*.spec.{js,ts,tsx}"],
      "globals": {
        "jest": true
      }
    },
    {
      "files": ["*.yaml", "*.yml"],
      "parser": "yaml-eslint-parser",

      "rules": {
        "prettier/prettier": 0,
        "comma-dangle": 0,
        "eol-last": "error"
      }
    },

    {
      "files": ["*.json"],

      "rules": {
        "prettier/prettier": 0,
        "comma-dangle": 0,
        "eol-last": "error",
        "json-files/sort-package-json": 2,
        "json/*": ["error", "allowComments"]
      }
    },
    {
      "files": ["*.spec.*", "jest.*.*", "./src/mocks/**/*.*"],
      "globals": {
        "globalThis": false
      }
    },
    {
      "files": ["*.{ts,tsx}"],

      "parser": "@typescript-eslint/parser",

      "plugins": ["@typescript-eslint"],
      "parserOptions": {
        "project": "./tsconfig.eslint.json"
      },

      "rules": {
        "no-duplicate-imports": ["error", { "includeExports": false }],
        "no-use-before-define": "off",
        "import/named": 0,
        "import/no-unresolved": 2,
        "@typescript-eslint/camelcase": 0,
        "@typescript-eslint/explicit-function-return-type": 0,
        "@typescript-eslint/explicit-module-boundary-types": 0,
        "@typescript-eslint/no-non-null-assertion": 0,
        "@typescript-eslint/no-explicit-any": 2,
        "@typescript-eslint/prefer-namespace-keyword": 0,
        "@typescript-eslint/no-namespace": 0,
        "@typescript-eslint/no-use-before-define": 2,
        "@typescript-eslint/no-floating-promises": 2,
        "@typescript-eslint/no-unused-vars": [
          "error",
          {
            "argsIgnorePattern": "^_",
            "varsIgnorePattern": "^_",
            "ignoreRestSiblings": true
          }
        ]
      },

      "extends": [
        "plugin:import/typescript",
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier"
      ]
    }
  ],

  "rules": {
    "comma-dangle": [2, "always-multiline"],
    "no-warning-comments": "off",
    "no-unused-vars": [
      "error",
      { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
    ],

    "no-duplicate-imports": ["error", { "includeExports": true }],
    "no-restricted-imports": [
      "error",
      {
        "paths": [
          {
            "name": "@testing-library/react",
            "message": "Please use import from './mocks/testUtils' instead."
          }
        ]
      }
    ],
    "promise/always-return": "off",
    "promise/no-return-wrap": "error",
    "promise/param-names": "error",
    "promise/catch-or-return": "error",
    "promise/no-native": "off",
    "promise/no-nesting": "off",
    "promise/no-promise-in-callback": "off",
    "promise/no-callback-in-promise": "off",
    "promise/avoid-new": "off",

    "react/no-multi-comp": [2, { "ignoreStateless": true }],
    "react/no-unused-prop-types": 2,
    "react/jsx-equals-spacing": [2, "never"],
    "react/jsx-handler-names": [0, {}],
    "react/jsx-pascal-case": [
      2,
      {
        "allowAllCaps": true,
        "ignore": []
      }
    ],

    "react/require-render-return": 2,
    "react-hooks/rules-of-hooks": 2,
    "react-hooks/exhaustive-deps": 2,
    "require-jsdoc": 0,

    "import/default": 2,
    "import/export": 2,
    "import/imports-first": 2,
    "import/named": 2,
    "import/namespace": 2,
    "import/no-deprecated": 2,
    "import/no-duplicates": 2,
    "import/no-mutable-exports": 2,
    "import/no-named-as-default": 2,
    "import/no-named-as-default-member": 2,
    "import/no-useless-path-segments": 2,
    "import/newline-after-import": 2,
    "import/no-extraneous-dependencies": [
      2,
      {
        "devDependencies": [
          "jest.*",
          "webpack.config.js",
          "**/*.spec.js",
          "**/*.spec.ts",
          "**/*.spec.tsx",
          "src/mocks/*"
        ]
      }
    ],
    "import/no-unresolved": [2, { "ignore": ["hiddenVariables"] }],

    "import/order": [
      "error",
      {
        "alphabetize": { "order": "asc", "caseInsensitive": true },
        "newlines-between": "never",
        "pathGroups": [
          {
            "pattern": "react",
            "group": "external",
            "position": "before"
          },
          {
            "pattern": "@adsk/**",
            "group": "external",
            "position": "after"
          }
        ],
        "groups": [["builtin", "external"], "internal"],
        "pathGroupsExcludedImportTypes": ["builtin", "react"]
      }
    ],

    "testing-library/no-node-access": 0,
      }
    ]
  },

  "extends": [
    "@adsk/eslint-config-autodesk",
    "plugin:no-unsanitized/DOM",
    "plugin:jest/recommended",
    "plugin:jest-dom/recommended",
    "plugin:json/recommended",
    "plugin:react/recommended",
    "plugin:prettier/recommended",
    "plugin:yml/standard"
  ]
}

Any help or guidance on resolving this issue and ensuring Eslint correctly recognizes the declaration module statement would be greatly appreciated. Thank you!

@tzachbon tzachbon changed the title Eslint import/no-unresolved error despite correct 'declare module' and TypeScript resolution [BUG] import/no-unresolved error despite correct 'declare module' and TypeScript resolution Apr 10, 2023
@akrsh24
Copy link

akrsh24 commented Apr 18, 2023

I am facing this issue too. Just checking this thread if we have any resolution till now.

@akrsh24
Copy link

akrsh24 commented Apr 21, 2023

Update: I was able to resolve this issue. I messed up by tsconfig.json and due to this my dist folder of the imported package, doesn't have the index.ts file generated.

@fsdkarthik
Copy link

I am facing a similar issue as reported by tzachbon. If you can prioritize fixing this issue, I would really appreciate your effort.

Issue:
Unable to resolve path to module 'myModule'.eslintimport/no-unresolved

eslintrc:
"import/resolver": { "typescript": { "alwaysTryTypes": true, "project": [ "./tsconfig.json" ] }, "node": { "extensions": [ ".d.ts", ".ts" ], "paths": [ "node_modules/@types", "src/types" ] } }

module:
declare module 'myModule' { let testName: string; }

tsconfig:
"typeRoots": ["./src/types"],

@ShadiestGoat
Copy link

Bump! Same thing.

Perhaps #197 should be closed in favor of this issue for tracking?

@JounQin
Copy link
Collaborator

JounQin commented Nov 20, 2023

Yes, same thing, so close due to duplicate.

@JounQin JounQin closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants