ad-on-is / adonis-autoswagger

Auto-Generate swagger docs for AdonisJS
MIT License
97 stars 32 forks source link

Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. #98

Closed FaiezWaseem closed 1 week ago

FaiezWaseem commented 2 weeks ago

Hi upon running node ace docs:generate it worked before , but now after adding vinejs and validations now on running this command suddenly i am getting this error

[ error ] Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, abs olute paths must be valid file:// URLs. Received protocol 'c:' at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11) at defaultLoad (node:internal/modules/esm/load:130:3) at nextLoad (node:internal/modules/esm/hooks:750:28) at C:\Development\web\node\adonijs-nextjs\server\node_modules\ts-node\src\esm.ts:255:45 at async addShortCircuitFlag (C:\Development\web\node\adonijs-nextjs\server\node_modules\ts-node\src\esm. ts:409:15) at async nextLoad (node:internal/modules/esm/hooks:750:22) at async Hooks.load (node:internal/modules/esm/hooks:383:20) at async handleMessage (node:internal/modules/esm/worker:199:18)

mGGk-fr commented 2 weeks ago

I have the same after updating to latest AdonisJS

ad-on-is commented 2 weeks ago

Oh boy... I hate the JS stack 🙄 will have a look into it

ad-on-is commented 2 weeks ago

Is this a Windows-only error, or a Node version error? https://stackoverflow.com/questions/69665780/error-err-unsupported-esm-url-scheme-only-file-and-data-urls-are-supported-by

I can't reproduce it on Linux with Node v21.6.1

ad-on-is commented 2 weeks ago

I just deployed a possible fix in 3.47.0. Can you guys test it with that version? Otherwise I might need some help here from the windows folks.

FaiezWaseem commented 2 weeks ago

@ad-on-is Ok i will test it now

FaiezWaseem commented 2 weeks ago

well So I tried the update . When i run the command node ace docs:generate , it runs successfully but when visits the docs error1

But when i debug a little more i added this route

router.get('/swagger.json', async () => {
  const json = fs.readFile('swagger.json','utf8')
  return AutoSwagger.default.writeFile(json, swagger);
});

now its giving this error

out+error

but comment.ts exists , it have already created the swagger.json

swagger

here is the github repo of my project

Node v21.7.3 AdonisJs ^6.9.0 adonis-autoswagger ^3.47.0

ad-on-is commented 1 week ago

Thx for the reproduction... This is an issue with node ace serve --hmr Using node ace serve --watch however, works as expected.

ad-on-is commented 1 week ago

@FaiezWaseem

Also... your config is wrong here.

router.get("/swagger", async () => {
  return router.toJSON()
});
router.get("/docs", async () => {
  return AutoSwagger.default.ui("/swagger", swagger);
});

should be

router.get("/swagger", async () => {
  return AutoSwagger.default.docs(swagger);
});
router.get("/docs", async () => {
  return AutoSwagger.default.ui("/swagger", swagger);
});
ad-on-is commented 1 week ago

Close in favor of https://github.com/ad-on-is/adonis-autoswagger/issues/102

FaiezWaseem commented 1 week ago

Yup fixed Working now