You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since some 3rd party librairies I use in my project are now only packaged for ESM, I decided to migrate my TypeScript project from CommonJS to ESM ("module": "nodenext" and "moduleResolution": "nodenext" in tsconfig.json)
I have an issue with fastify-metrics: when registering, the type of metricsPlugin is no longer considered as matching the expected type :
import metricsPlugin from 'fastify-metrics'
...
fastify.register(metricsPlugin, { endpoint: '/metrics' })
=>
src/app.ts:52:18 - error TS2769: No overload matches this call.
Overload 1 of 3, '(plugin: FastifyPluginCallback<{ endpoint: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'typeof import("/workspace/coucou/server/node_modules/fastify-metrics/dist/index")' is not assignable to parameter of type 'FastifyPluginCallback<{ endpoint: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
Type 'typeof import("/workspace/coucou/server/node_modules/fastify-metrics/dist/index")' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }, done: (err?: Error | undefined) => void): void'.
Overload 2 of 3, '(plugin: FastifyPluginAsync<{ endpoint: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'typeof import("/workspace/coucou/server/node_modules/fastify-metrics/dist/index")' is not assignable to parameter of type 'FastifyPluginAsync<{ endpoint: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
Type 'typeof import("/workspace/coucou/server/node_modules/fastify-metrics/dist/index")' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }): Promise<...>'.
Overload 3 of 3, '(plugin: FastifyPluginCallback<{ endpoint: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'typeof import("/workspace/coucou/server/node_modules/fastify-metrics/dist/index")' is not assignable to parameter of type 'FastifyPluginCallback<{ endpoint: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>'.
52 fastify.register(metricsPlugin, { endpoint: '/metrics' })
Am I doing something wrong? It worked when my project was CommonJS.
As a workaround I did this:
fastify.register(metricsPlugin as unknown as FastifyPluginAsync<Partial<IMetricsPluginOptions>>, {
endpoint: '/metrics'
})
The text was updated successfully, but these errors were encountered:
Hi. This plugin doesn't support ESM. And for now I don't have a plans for making it ESM-compatible. However if you want to try implement ESM support, you're more than welcome.
Since some 3rd party librairies I use in my project are now only packaged for ESM, I decided to migrate my TypeScript project from CommonJS to ESM (
"module": "nodenext"
and"moduleResolution": "nodenext"
intsconfig.json
)I have an issue with
fastify-metrics
: when registering, the type ofmetricsPlugin
is no longer considered as matching the expected type :=>
Am I doing something wrong? It worked when my project was CommonJS.
As a workaround I did this:
The text was updated successfully, but these errors were encountered: