i'm trying to use @fastify/cors but for some reason it can't resolve. i'm using esm in my repo and thats what i get:
import cors
No overload matches this call.
Overload 1 of 3, '(plugin: FastifyPluginCallback<{}, RawServerDefault, FastifyTypeProvider>, opts?: FastifyRegisterOptions<{}> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'typeof import("c:/Users/One1/Desktop/service-products/node_modules/@fastify/cors/index")' is not assignable to parameter of type 'FastifyPluginCallback<{}, RawServerDefault, FastifyTypeProvider>'.
Type 'typeof import("c:/Users/One1/Desktop/service-products/node_modules/@fastify/cors/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<{}, RawServerDefault, FastifyTypeProvider>, opts?: FastifyRegisterOptions<{}> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'typeof import("c:/Users/One1/Desktop/service-products/node_modules/@fastify/cors/index")' is not assignable to parameter of type 'FastifyPluginAsync<{}, RawServerDefault, FastifyTypeProvider>'.
Type 'typeof import("c:/Users/One1/Desktop/service-products/node_modules/@fastify/cors/index")' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: {}): Promise<...>'.
Overload 3 of 3, '(plugin: FastifyPluginCallback<{}, RawServerDefault, FastifyTypeProvider> | FastifyPluginAsync<{}, RawServerDefault, FastifyTypeProvider> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'typeof import("c:/Users/One1/Desktop/service-products/node_modules/@fastify/cors/index")' is not assignable to parameter of type 'FastifyPluginCallback<{}, RawServerDefault, FastifyTypeProvider> | FastifyPluginAsync<{}, RawServerDefault, FastifyTypeProvider> | Promise<...> | Promise<...>'.ts(2769)
ignore the ***
this is the code:
import { fastify } from "fastify";
import { routes } from "./routes/products.js";
import cors from "@fastify/cors";
const server = fastify({ logger: true });
await server.register(cors, {});
server.register(routes, { prefix: "/api/v1" });
try {
await server.listen({ port: 8082 });
console.log("Server is running at port 8082");
} catch (err) {
console.log(err);
process.exit(1);
}
this is my tsconfig.json:
{
"extends": "ts-node/node16/tsconfig.json",
"ts-node": {
"swc": true,
"esm": true
},
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"esModuleInterop": true,
"lib": ["es2021"],
"module": "ESNext",
"moduleResolution": "NodeNext",
"outDir": "./dist",
"strict": true,
"isolatedModules": true,
"resolveJsonModule": true,
"target": "ES2017"
},
"include": ["src/**/*"]
}