Open brnbs opened 1 week ago
@brnbs Hi! Could you please try latest 1.0.6 version and let me know?
Same error messages using 1.0.6: [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 'w:'
@brnbs I see.
Could you help me to test this situation a bit more?
Create two files (test-rule.js
and dynamic-esm-import.mjs
):
// test-rule.js
export default class TestRule {
constructor() {
console.log("Test rule loaded!");
}
}
and
// dynamic-esm-import.mjs
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
async function dynamicImport(modulePath) {
try {
console.log(`[dynamicImport] Attempting to import from path: ${modulePath}`);
const importedModule = await import(modulePath);
console.log("[dynamicImport] Imported module:", importedModule);
const instance = new importedModule.default();
} catch (error) {
console.error("[dynamicImport] Error in dynamic import:", error);
}
}
async function dynamicImportAlternative(modulePath) {
try {
console.log(`[dynamicImportAlternative] Attempting to import from path: ${modulePath}`);
const importedModule = await import(modulePath);
console.log("[dynamicImportAlternative] Imported module:", importedModule);
const instance = new importedModule.default();
} catch (error) {
console.error("[dynamicImportAlternative] Error in dynamic import:", error);
}
}
dynamicImport(path.join(__dirname, './test-rule.js'));
dynamicImportAlternative(pathToFileURL(path.join(__dirname, './test-rule.js')).href);
and run them:
node dynamic-esm-import.mjs
Do you see same errors?
@brnbs Also do you experience the same error if using docker image?
I got the same error:
PS W:\Projects\test> node dynamic-esm-import.mjs
[dynamicImport] Attempting to import from path: W:\Projects\test\test-rule.js
[dynamicImportAlternative] Attempting to import from path: file:///W:/Projects/test/test-rule.js
[dynamicImport] Error in dynamic import: 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 'w:'
at new NodeError (node:internal/errors:405:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:149:11)
at defaultLoad (node:internal/modules/esm/load:99:3)
at ModuleLoader.load (node:internal/modules/esm/loader:417:13)
at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:288:22)
at new ModuleJob (node:internal/modules/esm/module_job:63:26)
at #createModuleJob (node:internal/modules/esm/loader:312:17)
at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:265:34)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:251:17)
at async ModuleLoader.import (node:internal/modules/esm/loader:336:23) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
(node:11208) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[dynamicImportAlternative] Error in dynamic import: W:\Projects\test\test-rule.js:2
export default class TestRule {
^^^^^^
SyntaxError: Unexpected token 'export'
at internalCompileFunction (node:internal/vm:76:18)
at wrapSafe (node:internal/modules/cjs/loader:1283:20)
at Module._compile (node:internal/modules/cjs/loader:1328:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:203:29)
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
at async dynamicImportAlternative (file:///W:/Projects/test/dynamic-esm-import.mjs:21:32)
I also did a test with an extra package.json file with the "type": "module"
line:
PS W:\Projects\test> node dynamic-esm-import.mjs
[dynamicImport] Attempting to import from path: W:\Projects\test\test-rule.js
[dynamicImportAlternative] Attempting to import from path: file:///W:/Projects/test/test-rule.js
[dynamicImport] Error in dynamic import: 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 'w:'
at new NodeError (node:internal/errors:405:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:149:11)
at defaultLoad (node:internal/modules/esm/load:99:3)
at ModuleLoader.load (node:internal/modules/esm/loader:417:13)
at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:288:22)
at new ModuleJob (node:internal/modules/esm/module_job:63:26)
at #createModuleJob (node:internal/modules/esm/loader:312:17)
at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:265:34)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:251:17)
at async ModuleLoader.import (node:internal/modules/esm/loader:336:23) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
[dynamicImportAlternative] Imported module: [Module: null prototype] { default: [class TestRule] }
Test rule loaded!
The docker run -t --rm -v ${PWD}:/app zavoloklom/dclint .
command works fine in the same W:/Projects/test
directory on 2 yml files.
Version
1.0.3
YAML file where the error occurs
N/A
Command used to run
I have my project folder on my W: drive, but I also tried moving the project to my C: drive. I tried with the npx version and the locally installed version. Every variation has the same end result, described below.
npx dclint .
npx dclint .\docker-compose.outline.yaml
.\node_modules\.bin\dclint.cmd .
Optional configuration (if different from the default)
N/A
Additional context
Windows 11, Node 18.20.4
I created a Dev Drive with the drive letter W, and moved the npm cache folder to there using the following user environment variable:
npm_config_cache=W:\System\npm_cache
I suspect this configuration is causing the issue because even if I run the command from my C: drive, the error message contains the W: drive (
Received protocol 'w:'
).Current behavior (console output)
Expected behavior
The command should lint my files.