| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 969fb1c commit 8f38c19
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,8 @@ const { | |||
| 26 | 26 | WeakMap, | |
| 27 | 27 | } = primordials; | |
| 28 | 28 | ||
| 29 | + const isWindows = process.platform === 'win32'; | ||
| 30 | + | ||
| 29 | 31 | const messages = new Map(); | |
| 30 | 32 | const codes = {}; | |
| 31 | 33 | ||
@@ -1410,8 +1412,15 @@ E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError); | |||
| 1410 | 1412 | E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError); | |
| 1411 | 1413 | E('ERR_UNSUPPORTED_DIR_IMPORT', "Directory import '%s' is not supported " + | |
| 1412 | 1414 | 'resolving ES modules imported from %s', Error); | |
| 1413 | - E('ERR_UNSUPPORTED_ESM_URL_SCHEME', 'Only file and data URLs are supported ' + | ||
| 1414 | - 'by the default ESM loader', Error); | ||
| 1415 | + E('ERR_UNSUPPORTED_ESM_URL_SCHEME', (url) => { | ||
| 1416 | + let msg = 'Only file and data URLs are supported by the default ESM loader'; | ||
| 1417 | + if (isWindows && url.protocol.length === 2) { | ||
| 1418 | + msg += '. Absolute Windows paths without prefix are not valid URLs, ' + | ||
| 1419 | + "consider using 'file://' prefix"; | ||
| 1420 | + } | ||
| 1421 | + msg += `. Received protocol '${url.protocol}'`; | ||
| 1422 | + return msg; | ||
| 1423 | + }, Error); | ||
| 1415 | 1424 | ||
| 1416 | 1425 | // This should probably be a `TypeError`. | |
| 1417 | 1426 | E('ERR_VALID_PERFORMANCE_ENTRY_TYPE', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -747,7 +747,7 @@ function defaultResolve(specifier, context = {}, defaultResolveUnused) { | |||
| 747 | 747 | if (parsed && parsed.protocol === 'nodejs:') | |
| 748 | 748 | return { url: specifier }; | |
| 749 | 749 | if (parsed && parsed.protocol !== 'file:' && parsed.protocol !== 'data:') | |
| 750 | - throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(); | ||
| 750 | + throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed); | ||
| 751 | 751 | if (NativeModule.canBeRequiredByUsers(specifier)) { | |
| 752 | 752 | return { | |
| 753 | 753 | url: 'nodejs:' + specifier | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,15 +8,11 @@ const absolutePath = require.resolve('../fixtures/es-modules/test-esm-ok.mjs'); | |||
| 8 | 8 | const targetURL = new URL('file:///'); | |
| 9 | 9 | targetURL.pathname = absolutePath; | |
| 10 | 10 | ||
| 11 | - function expectErrorProperty(result, propertyKey, value) { | ||
| 12 | - Promise.resolve(result) | ||
| 13 | - .catch(common.mustCall((error) => { | ||
| 14 | - assert.strictEqual(error[propertyKey], value); | ||
| 15 | - })); | ||
| 16 | - } | ||
| 17 | - | ||
| 18 | - function expectModuleError(result, err) { | ||
| 19 | - expectErrorProperty(result, 'code', err); | ||
| 11 | + function expectModuleError(result, code, message) { | ||
| 12 | + Promise.resolve(result).catch(common.mustCall((error) => { | ||
| 13 | + assert.strictEqual(error.code, code); | ||
| 14 | + if (message) assert.strictEqual(error.message, message); | ||
| 15 | + })); | ||
| 20 | 16 | } | |
| 21 | 17 | ||
| 22 | 18 | function expectOkNamespace(result) { | |
@@ -60,4 +56,13 @@ function expectFsNamespace(result) { | |||
| 60 | 56 | 'ERR_MODULE_NOT_FOUND'); | |
| 61 | 57 | expectModuleError(import('http://example.com/foo.js'), | |
| 62 | 58 | 'ERR_UNSUPPORTED_ESM_URL_SCHEME'); | |
| 59 | + if (common.isWindows) { | ||
| 60 | + const msg = | ||
| 61 | + 'Only file and data URLs are supported by the default ESM loader. ' + | ||
| 62 | + 'Absolute Windows paths without prefix are not valid URLs, ' + | ||
| 63 | + "consider using 'file://' prefix. Received protocol 'c:'"; | ||
| 64 | + expectModuleError(import('C:\\example\\foo.mjs'), | ||
| 65 | + 'ERR_UNSUPPORTED_ESM_URL_SCHEME', | ||
| 66 | + msg); | ||
| 67 | + } | ||
| 63 | 68 | })(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments