markcellus / markcellus/html-express-js
ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18
- Forks
- 3
- Avg merge
- 1m
- Merged PRs (30d)
- 5
Description
Hi,
I was getting the below error on my Windows machine.
node:internal/errors:484
ErrorCaptureStackTrace(err);
^
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (node:internal/errors:393:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:989:11)
at defaultResolve (node:internal/modules/esm/resolve:1069:3)
at nextResolve (node:internal/modules/esm/loader:161:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:831:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:413:18)
at ESMLoader.import (node:internal/modules/esm/loader:514:22)
at importModuleDynamically (node:internal/modules/esm/translators:110:35)
at importModuleDynamicallyCallback (node:internal/process/esm_loader:36:14)
at renderHtmlFileTemplate (file:///C:/Users/***/OneDrive/Desktop/workspace/testServer/node_modules/html-express-js/src/index.js:21:20) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
Node.js v19.2.0
Here is the diff that solved my problem:
diff --git a/node_modules/html-express-js/src/index.js b/node_modules/html-express-js/src/index.js
index 9d06c5c..954db82 100644
--- a/node_modules/html-express-js/src/index.js
+++ b/node_modules/html-express-js/src/index.js
@@ -15,6 +15,9 @@ const glob = promisify(g);
* @returns {Promise<string>} HTML
*/
async function renderHtmlFileTemplate(path, data, state) {
+ if(!path.startsWith('file:///')) {
+ path = 'file:///'+path;
+ }
const { view } = await import(path);
const rendered = view(data, state);
let html = '';
This issue body was partially generated by patch-package.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/index.js at renderHtmlFileTemplate, identified by the Windows stack trace, and inspect how its dynamic import receives paths. Reproduce the failure on Windows with an absolute path, then verify that the template renders successfully through the supported URL handling. The issue's supplied diff provides the reported expected direction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100