Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
EDM115 opened this issue Apr 23, 2024 · 8 comments · Fixed by egoist/bundle-require#43 or #46
Closed

Comments

@EDM115
Copy link

EDM115 commented Apr 23, 2024

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

  • Create a new nuxt project on another drive than C
  • Add an eslint config (flat format here)
  • Run the dev server, check the nuxt devtools and observe the above screenshot
@EDM115
Copy link
Author

EDM115 commented Apr 23, 2024

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

This comment was marked as duplicate.

@antfu
Copy link
Collaborator

antfu commented Apr 25, 2024

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

@LittleTurtle2333

This comment was marked as duplicate.

@Mallon94
Copy link

Mallon94 commented May 1, 2024

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
Copy link

Mallon94 commented May 1, 2024

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
Copy link
Author

EDM115 commented May 1, 2024

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
Copy link

meirroth commented May 2, 2024

@antfu Thank you for fixing this issue ❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants