eslint-plugin-node icon indicating copy to clipboard operation
eslint-plugin-node copied to clipboard

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

Open misha-erm opened this issue 5 years ago • 2 comments

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/**/*"]
}

misha-erm avatar Nov 13 '20 20:11 misha-erm

Additional context: [email protected]

// ./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.

younho9 avatar Oct 05 '21 03:10 younho9

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

Toilal avatar Feb 26 '22 20:02 Toilal