ITADN

Cannot import fastify-html using default import in TypeScript: "Module ... has no default export.ts(1192)"

#24ClosedGiovanniSlabs 创建于 2025-01-03
bug
G
GiovanniSlabscommented
Hello, I’m encountering a TypeScript error when attempting to use a default import with fastify-html. My code looks like this: ``` import fastifyHtml from 'fastify-html'; import fp from 'fastify-plugin' export default fp(async (fastify) => { await fastify.register(fastifyHtml, { async: true }); fastify.addLayout(function (inner, reply) { return fastify.html` <!DOCTYPE html> <html> <head> </head> <body> !${inner} </body> </html>` }, { skipOnHeader: 'hx-request' }) }); ``` ![image](https://github.com/user-attachments/assets/34821180-6f09-4d29-a7f4-4b5a9ef5e183) But when I compile, I get: Module '"/path/to/node_modules/fastify-html/types/plugin"' has no default export.ts(1192) My tsconfig.json is: `{ "extends": "fastify-tsconfig", "compilerOptions": { "esModuleInterop": true, "allowSyntheticDefaultImports": true, "allowJs": true, "outDir": "dist", "sourceMap": true }, "include": [ "src/**/*.ts", "src/**/*.js" ] }` Thanks for looking into this!
关闭于 2025-05-19 2 条评论