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

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

Closed
renkei opened this issue Jun 5, 2022 · 8 comments
Closed

Comments

@renkei
Copy link

renkei commented Jun 5, 2022

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?

@renkei renkei changed the title Changes for ESM support with express-openapi 12.0.0 break whole app on Windows Initialize() of express-openapi 12.0.0 always throws exception on Windows Jun 5, 2022
@renkei renkei changed the title Initialize() of express-openapi 12.0.0 always throws exception on Windows initialize() of express-openapi 12.0.0 always throws exception on Windows Jun 5, 2022
@jsdevel
Copy link
Contributor

jsdevel commented Jun 6, 2022

@robertkiel can you help here?

@robertkiel
Copy link
Contributor

@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.

@renkei
Copy link
Author

renkei commented Jun 9, 2022

Any update on this?

@jsdevel
Copy link
Contributor

jsdevel commented Jun 15, 2022

@robertkiel would be great if you could provide some leadership/help here.

@robertkiel
Copy link
Contributor

@robertkiel would be great if you could provide some leadership/help here.

Sorry for the late reply. Have been busy with a different issue - also related ESM migrations which brought some insights

Need to create a Windows-based test setup first but it looks like most prefixing with file:/// can work for many platforms.

@jsdevel
Copy link
Contributor

jsdevel commented Jun 20, 2022

@renkei can you try now with 12.0.1? @robertkiel just pushed up a fix.

@renkei
Copy link
Author

renkei commented Jun 27, 2022

Thanks! It works on Windows again.

@renkei renkei closed this as completed Jun 27, 2022
@jsdevel
Copy link
Contributor

jsdevel commented Jun 30, 2022

thanks for stepping in @robertkiel !!!

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

No branches or pull requests

3 participants