Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Unable to resolve path to module 'typescript-eslint' #345

Open
RashiqAzhan opened this issue Apr 2, 2024 · 1 comment
Open

Unable to resolve path to module 'typescript-eslint' #345

RashiqAzhan opened this issue Apr 2, 2024 · 1 comment

Comments

@RashiqAzhan
Copy link

RashiqAzhan commented Apr 2, 2024

Shouldn't import/no-unresolved be off by default according to the docs? It seems to not be working as expected for my case.

package.json

{
  "name": "typescript-eslint-airbnb-compat",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview",
    "lint": "eslint .",
    "lint:fix": "npm run lint -- --fix",
    "format": "prettier . --check",
    "format:fix": "npm run format -- --write"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3.0.2",
    "@eslint/js": "^8.57.0",
    "@typescript-eslint/eslint-plugin": "^7.5.0",
    "@typescript-eslint/parser": "^7.5.0",
    "eslint": "^8.57.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-config-airbnb-typescript": "^18.0.0",
    "eslint-plugin-import": "^2.25.2",
    "eslint-config-prettier": "^9.1.0",
    "tslib": "^2.6.2",
    "typescript": "^5.4.3",
    "typescript-eslint": "^7.4.0",
    "vite": "^5.2.0"
  }
}

eslint.config.mjs

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintConfigPrettier from "eslint-config-prettier";

import { FlatCompat } from "@eslint/eslintrc";
import path from "path";
import { fileURLToPath } from "url";

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);

const compat = new FlatCompat({
  baseDirectory: dirname
});

export default tseslint.config(
  eslint.configs.recommended,
  ...compat.extends("airbnb-base"),
  ...compat.extends("airbnb-typescript/base"),
  ...tseslint.configs.recommendedTypeChecked,
  eslintConfigPrettier,
  {
    languageOptions: {
      parserOptions: {
        project: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
  {
      files: ['**/*.{js,jsx,cjs,mjs}'],
      extends: [tseslint.configs.disableTypeChecked],
  }
);

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"]
}

Terminal Output:

.../typescript-eslint-airbnb-compat/eslint.config.mjs
 2:22  error  Unable to resolve path to module 'typescript-eslint'                                          import/no-unresolved
@Kenneth-Sills
Copy link

Gah, this is going to go a bit into the drama side of FOSS. In case they see this, I want to preempt this comment by saying a huge thank you for all the work they've done in open source. It's thankless work but has provided oodles of value for the world. Everyone has a right to maintain their projects how they see fit and value different priorities in how software is developed/maintained. This is just coming a downstream dev affected by it all.


import/no-unresolved is only disabled for .ts and .tsx files, because Typescript handles this for us. Javascript files like eslint.config.mjs still have the rule enabled.

Unfortunately, the upstream eslint-plugin-import package this rule comes from has a longstanding bug in that it can't use exports from package.json, which causes monorepo plugins like typescript-eslint to become unresolvable. And the maintainer of that project is... controversial (see the hidden thread in the linked ticket). That same maintainer controls resolve, which is where the inability to read exports comes from.

Alternative projects like eslint-plugin-import-x exist, fixing that bug among others using enhanced-resolve... So you may suggest we (or Airbnb, really) just switch over like other projects have, but the same maintainer holds onto the upstream Airbnb configs and has... less than favorable views on forks of his projects. With those threads getting locked, there's pretty much no way to talk about it anymore and I, personally, have little desire to get involved.

So, long story short, what you can do:

  1. Turn off the rule, or skip it on dependencies that use exports.
  2. Switch over to eslint-import-resolver-typescript or eslint-plugin-import-x.

@iamturns I think it would be in the best interest of our users if we disabled these import rules from upstream and swapped them for one of these instead. We would still leave the rules disabled for .ts and .tsx by default, of course, but it would be nice for this project to be as plug-and-play as possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants