How to import this in Nuxt3
ShoWerZen opened this issue · 4 comments
ShoWerZen commented
I defined a file in plugins folder.
import PwaInstall from '@khmyznikov/pwa-install';
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.use(PwaInstall);
});
Use this component in my install page got this error.
[nuxt] [request error] [unhandled] [500] Cannot convert object to primitive value 10:41:03
at ./@khmyznikov/pwa-install:4:1773
at async ViteNodeRunner.directRequest (./node_modules/vite-node/dist/client.mjs:312:5)
at async ViteNodeRunner.cachedRequest (./node_modules/vite-node/dist/client.mjs:156:14)
at async ViteNodeRunner.dependencyRequest (./node_modules/vite-node/dist/client.mjs:204:14)
at async ./plugins/pwaInstall.js:3:31
at async ViteNodeRunner.directRequest (./node_modules/vite-node/dist/client.mjs:312:5)
at async ViteNodeRunner.cachedRequest (./node_modules/vite-node/dist/client.mjs:156:14)
at async ViteNodeRunner.dependencyRequest (./node_modules/vite-node/dist/client.mjs:204:14)
at async ./virtual:nuxt:/Users/showerzen/wap/.nuxt/plugins/server.mjs:21:32
at async ViteNodeRunner.directRequest (./node_modules/vite-node/dist/client.mjs:312:5)
ShoWerZen commented
I change plugins file as pwa-install.client.ts
import { PWAInstallElement } from '@khmyznikov/pwa-install';
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.component('pwa-install', PWAInstallElement);
});
No error log but component not shown.
ShoWerZen commented
Solution below:
- plugins/pwa-install.client.ts
import { PWAInstallElement } from '@khmyznikov/pwa-install';
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.component('pwa-install', PWAInstallElement);
});
- nuxt.config.ts
vue: {
compilerOptions: {
isCustomElement: tag => tag === 'pwa-install'
}
},
khmyznikov commented
Yep. Because Nuxt is based on Vue, you need to tell Vue about new custom element