question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

initialize() of express-openapi 12.0.0 always throws exception on Windows

See original GitHub issue

After the update to express-openapi 12.0.0 my CommonJS app crashes on Windows when I’m calling the initialize method from the express-openapi package:

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:372:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1120:11)
    at defaultResolve (node:internal/modules/esm/resolve:1200:3)
    at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
    at ESMLoader.import (node:internal/modules/esm/loader:380:22)
    at importModuleDynamically (node:internal/modules/cjs/loader:1043:29)
    at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
    at importModuleDynamically (node:vm:381:46)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)

For Windows, the issue can be solved by changing in openapi-framework/index.ts, line 238

from

const imported = await import(fsRoutesItem.path);

to

const imported = await import(`file:///${fsRoutesItem.path}`);

Of course, this is just a first dirty hack and not tested on other platforms than Windows. Can someone check this and provide a fixed version 12.0.1, please?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
robertkielcommented, Jun 6, 2022

@robertkiel can you help here?

Haven’t tested the change on Windows yet … The CommonJS script / ES module loader of Node.js seems to require some special treatment for Windows.

Will try on Windows tomorrow.

1reaction
renkeicommented, Jun 27, 2022

Thanks! It works on Windows again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

express-openapi - npm
initialize (args). Initializes paths and middleware on an express app, and returns an initialized api. An initialized api contains the following ...
Read more >
How to use the express-openapi.initialize function in ... - Snyk
To help you get started, we've selected a few express-openapi.initialize examples, based on popular ways it is used in public projects.
Read more >
Bad error message if operationId is not specified #465 - GitHub
When calling initialize with an apiDoc that has an operation that is missing an operationId, express-openapi emits a warning and then throws ......
Read more >
Could not load file or assembly 'Newtonsoft.Json, Version=9.0 ...
But when I run the application and call a Native method in Windows Runtime Component it gives some kind of strange errors as:...
Read more >
netlify-cli | Yarn - Package Manager
Generate a handler for a Graph operation given its name. See graph:operations for a list of operations. graph:init, Initialize all the resources for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found