mysticatea / eslint-plugin-node

Additional ESLint's rules for Node.js
MIT License
959 stars 170 forks source link

no-missing-import conflicts with typescript compiling to ES modules #248

Open misha-erm opened 3 years ago

misha-erm commented 3 years ago

Hello, I'm using TypeScript project which compiles to ES modules. Because of this imports should containt '.js' extension like: import {config} from './config.js'; The problem is that actually there is config.ts file and looks like no-missing-imports can't compare them.

Thanks in advance for your help. Here are my configs:

.eslintrc:

{
    "parser": "@typescript-eslint/parser",
    "env": {
        "jest": true,
        "node": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:node/recommended",
        "plugin:jest/recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier/@typescript-eslint",
        "prettier"
    ],
    "parserOptions": {
        "ecmaVersion": 2020
    },
    "rules": {
        "node/no-unpublished-import": 0,
        "node/no-missing-import": 0
    }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "outDir": "dist",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  },
  "include": ["src/**/*"]
}
younho9 commented 3 years ago

Additional context: typescript@4.5

// ./bar.ts
import { helper } from "./foo.js"; // works in ESM & CJS

helper();

This might feel a bit cumbersome at first, but TypeScript tooling like auto-imports and path completion will typically just do this for you.

Toilal commented 2 years ago

Workaround for this issue: disable node/no-missing-import rule and use eslint-plugin-import with eslint-import-resolver-typescript.