ad-on-is / adonis-autoswagger

Auto-Generate swagger docs for AdonisJS
MIT License
129 stars 41 forks source link

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

Closed FaiezWaseem closed 4 months ago

FaiezWaseem commented 5 months 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 5 months ago

I have the same after updating to latest AdonisJS

ad-on-is commented 5 months ago

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

ad-on-is commented 4 months 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 4 months 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 4 months ago

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

FaiezWaseem commented 4 months 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 4 months 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 4 months 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 4 months ago

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

FaiezWaseem commented 4 months ago

Yup fixed Working now