darkobits / vite-plugin-favicons

💅 Generate favicons for your Vite project.
Other
8 stars 1 forks source link

"TypeError: faviconsPlugin is not a function" with vite 4.0.4 #12

Closed zu1k closed 1 year ago

zu1k commented 1 year ago

I'm upgrating @darkobits/vite-plugin-favicons to 0.2.0 in https://github.com/book-searcher-org/book-searcher/blob/master/frontend/package.json

I got TypeError: faviconsPlugin is not a function, when using 0.1.8 everything works fine.

failed to load config from /home/alex/projects/book-searcher/frontend/vite.config.ts
error during build:
TypeError: faviconsPlugin is not a function
    at file:///home/alex/projects/book-searcher/frontend/vite.config.ts.timestamp-1674873223959.mjs:68:40
    at loadConfigFromFile (file:///home/alex/projects/book-searcher/frontend/node_modules/.pnpm/vite@4.0.4_@types+node@18.11.18/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:61972:15)
    at async resolveConfig (file:///home/alex/projects/book-searcher/frontend/node_modules/.pnpm/vite@4.0.4_@types+node@18.11.18/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:61590:28)
    at async doBuild (file:///home/alex/projects/book-searcher/frontend/node_modules/.pnpm/vite@4.0.4_@types+node@18.11.18/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:44358:20)
    at async build (file:///home/alex/projects/book-searcher/frontend/node_modules/.pnpm/vite@4.0.4_@types+node@18.11.18/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:44347:16)
    at async CAC.<anonymous> (file:///home/alex/projects/book-searcher/frontend/node_modules/.pnpm/vite@4.0.4_@types+node@18.11.18/node_modules/vite/dist/node/cli.js:808:9)
darkobits commented 1 year ago

Can you try changing esModuleInterop to true in your tsconfig.json and see if that doesn't resolve the issue?

If that fails, see if accessing faviconsPlugin.default fixes it.

Apologies for this unintended breaking change, I recently switched from compiling the project with Babel to using the TypeScript compiler directly, and it seems to have some subtle differences with respect to how it compiles default exports. I may just switch to a named export for this plugin to circumvent this issue entirely.

zu1k commented 1 year ago

Can you try changing esModuleInterop to true in your tsconfig.json and see if that doesn't resolve the issue?

I got the same error whether set esModuleInterop to true or false.

see if accessing faviconsPlugin.default fixes it

This can be successfully compiled, but the code inspection prompts that there is no default field. Is it because of the difference between index.d.ts and index.js?

darkobits commented 1 year ago

Alright, changed this to a named export. Update to v0.3.0 and update your import to:

import { faviconsPlugin } from '@darkobits/vite-plugin-favicons';

and you should be good.

zu1k commented 1 year ago
import { faviconsPlugin } from '@darkobits/vite-plugin-favicons';

This compiled successfully, but the code inspection prompts that Module '"@darkobits/vite-plugin-favicons"' has no exported member 'faviconsPlugin'.

zu1k commented 1 year ago

the code inspection prompts that Module '"@darkobits/vite-plugin-favicons"' has no exported member 'faviconsPlugin'.

Sorry for that, I restarted my vscode, then it reindex the code, everything works well.

Thank you!