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
518 stars 15 forks source link

[BUG] Doesn't work when the config is outside of `C:` drive on Windows #47

Closed EDM115 closed 2 months ago

EDM115 commented 2 months ago

Description

When the project is located on another drive, here's the error :

Failed to load eslint.config.js
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'

Screenshot

image

Reproducible scenario

EDM115 commented 2 months ago

here's what reports the Nuxt devtools terminal :

> node D:/EDM115/Documents/IUT/SAE 3.A.01/Tab-Magiques/node_modules/@eslint/config-inspector/bin.mjs --no-open

ℹ Starting ESLint config inspector at http://127.0.0.1:8123 

ℹ Reading ESLint config from D:\EDM115\Documents\IUT\SAE 3.A.01\Tab-Magiques\eslint.config.js
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 [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11)
    at defaultLoad (node:internal/modules/esm/load:130:3)
    at ModuleLoader.load (node:internal/modules/esm/loader:403:13)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:56)
    at new ModuleJob (node:internal/modules/esm/module_job:67:26)
    at #createModuleJob (node:internal/modules/esm/loader:297:17)
    at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:254:34)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:235:17)
    at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:21) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
meirroth commented 2 months ago

I'm experiencing the same issue on Windows.

antfu commented 2 months ago

It's likely a bug of https://github.com/egoist/bundle-require - if any one wants to help fixing it

LittleTurtle2333 commented 2 months ago

same issue

Mallon94 commented 2 months ago

I don't think its related to what drive its on. Happens on any drive. Seems to be that withNuxt isn't getting imported correctly.

Mallon94 commented 2 months ago

To fix this temporarily you can use pathToFileURL to get the correct file path then import with that. For example, in Nuxt you can replace the contents of your eslint.config.mjs with the below;


import { pathToFileURL } from 'url';
const fileURL = pathToFileURL('./.nuxt/eslint.config.mjs');
const withNuxt = await import(fileURL.href);

export default withNuxt.default({
 // custom config
})
EDM115 commented 2 months ago

withNuxt isn't getting imported correctly

honestly I don't even know why the documentation recommends using it. it requires the app to be built (to generate the .nuxt folder) before even be able to start linting (see this action run, it's at this point that I understood that I would need to run npm run build before each npm run lint-fix, and from there I searched another way to import it)

To fix this temporarily you can use pathToFileURL to get the correct file path then import with that

I get the idea, but I think a better thing would be to use another import :

import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

export default createConfigForNuxt(
  // config...
)

I don't see the benefit of using withNuxt over createConfigForNuxt, and on another topic I believe the documentation should recommend that way

meirroth commented 2 months ago

@antfu Thank you for fixing this issue ❤