fastify / fastify-swagger-ui

Serve Swagger-UI for Fastify
MIT License
134 stars 40 forks source link

Error: ENOENT: no such file or directory, open 'node:fs' #36

Closed raaymax closed 1 year ago

raaymax commented 1 year ago

Prerequisites

Fastify version

4.13.0

Plugin version

1.3.0

Node.js version

16.15.1

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.3.1

Description

I managed to find that node:fs is used by @fastify/send

│ ├┬ @fastify/swagger-ui@1.3.0
│ │  ├┬ @fastify/static@6.9.0
│ │ │   ├┬ @fastify/send@2.0.1

I want to use this plugin with node 16, can I work around it somehow?

Steps to Reproduce

Just use this version of @fastify/swagger-ui with node 16

Expected Behavior

No response

Uzlopak commented 1 year ago

Please elaborate.

raaymax commented 1 year ago

@fastify/send from version 2.0 is using new nodejs libraries prefix (node:) which is not recognized by node 16. in package.json there is

    "@fastify/static": "^6.0.0",

with ^ mark it will install newest possible minor version of library so it is installing 6.9.0. @fastify/static in version >6.7.0 introduces @fastify/send@2.0.0 which is not compatible with node 16 anymore.

I managed to force install @fastify/static@6.7.0 and it works now for me, but I think it should work like it out off the box without spending 3h on debugging.

Uzlopak commented 1 year ago

Thats odd because fastify send and fastify/swagger-ui are tested against node16

climba03003 commented 1 year ago

https://nodejs.org/dist/latest-v18.x/docs/api/esm.html#node-imports

node: prefix is added in v16.0.0, v14.18.0 for CJS and v14.13.1, v12.20.0 for ESM . If you believe it is not supported in your environment. You must check is it really running under 16.15.1.

Note that any third party loader module may screw you up. For example, esm.

raaymax commented 1 year ago

Indeed it's true! And you solved my problem! The actual issue was with our version of jest... It was so old it didn't have prefix support. Thank you so much!