eslint / config-inspector

A visual tool for inspecting and understanding your ESLint flat configs.
https://www.npmjs.com/package/@eslint/config-inspector
Apache License 2.0
738 stars 19 forks source link

Errors when running on `elint.config.mjs` #52

Closed vicary closed 3 months ago

vicary commented 6 months ago

My project is not ESM ready, therefore I have to use the .mjs extension to let only eslint use ESM.

The analyzer fails to pick up the config file, but fails with an irrelevant error message.

image

You can also run this command directly using 'npx @eslint/config-inspector' in the same directory as your configuration file.
ℹ Starting ESLint config inspector at http://127.0.0.1:7777 

ℹ Reading ESLint config from [REDACTED]/eslint.config.mjs
Failed to load `eslint.config.js`.
Note that `@eslint/config-inspector` only works with the flat config format:
https://eslint.org/docs/latest/use/configure/configuration-files-new
Error: Dynamic require of "tty" is not supported
    at file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:12:9
    at node_modules/debug/src/node.js (file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:610:15)
    at __require2 (file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:15:50)
    at node_modules/debug/src/index.js (file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:787:24)
    at __require2 (file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:15:50)
    at node_modules/@eslint/eslintrc/dist/eslintrc.cjs (file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:10517:21)
    at __require2 (file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:15:50)
    at file:///[REDACTED]/eslint.config.bundled_u7zfo621b2d.mjs:546154:31
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)

Is it possible to support eslint.config.mjs?

antfu commented 6 months ago

Can you share a minimal reproduction? Thanks

vicary commented 6 months ago

@antfu It turns out to be a unique combination of seemingly unrelated issues, please checkout this minrep https://github.com/vicary/eslint-config-inspector-mjs

All of the followings must be true to trigger this bug:

  1. Use eslint.config.mjs instead of eslint.config.js
  2. import @eslint/eslintrc in the file
  3. Add a tsconfig.json with a path of * pointing to anywhere

I am not sure how does tsconfig.json affects the require path of eslint.config.mjs, but it seems to be the culprit.

antfu commented 6 months ago

Why you are having "*": ["node_modules/*"] - it looks problematic to me. The config inspector use bundle-require to import the config file, which is powered by esbuild and respects your tsconfig.json. I would try to see if it's possible to disable tsconfig looking up - but I am not sure if your tsconfig.json is correct in the mean time

vicary commented 6 months ago

It is for a specific issue when the project root contains a directory with the same name as one of those inside node_modules.

When we have node_modules/graphql/ installed, our graphql/index.ts would break at the following import statement because the bare module identifier resolves to itself.

import * as graphql from "graphql";
clemyan commented 5 months ago

This happens whenever importing the config crosses from ESM into CJS. Minimal reproduction

Looks like a limitation of bundle-require

G-Rath commented 3 months ago

@antfu given you've done https://github.com/egoist/bundle-require/pull/45, should someone next be making a PR here to explicitly pass tsconfig: false when calling bundleRequire?