vueuse / schema-org

🔎 Quick and easy Schema.org graphs for Vue. Powered by Unhead.
https://unhead-schema-org.harlanzw.com
375 stars 21 forks source link

bug(nuxt): failed to find plugin #4

Closed oritwoen closed 2 years ago

oritwoen commented 2 years ago

Built project with the schema-org library.

[@vueuse/schema-org] Failed to find plugin, you may have forgotten to apply app.use(schemaOrg)

image

harlan-zw commented 2 years ago

Hey, i've tried to replicate this with the other reproduction repo you had and couldn't.

Are you able to provide some details on replicating and I'll try and get it sorted

oritwoen commented 2 years ago

@harlan-zw

I can't reproduce it online. I truncated my entire application to check if any component/page /module was causing a problem and I was left only with the app.vue file identical on stackblitz. And on stackblitz after building it works okey. For me, however, there is:


------------------------------
- Operating System: `Linux`
- Node Version:     `v16.15.0`
- Nuxt Version:     `3.0.0-rc.2`
- Package Manager:  `yarn@1.23.0-20220130.1630`
- Builder:          `vite`
- User Config:      `modules`, `schemaOrg`
- Runtime Modules:  `nuxt-schema-org@0.5.2`
- Build Modules:    `-`
Error: [@vueuse/schema-org] Failed to find plugin, you may have forgotten to apply app.use(schemaOrg)
    at injectSchemaOrg (file:///home/ririen/Projekty/Project/Website/.output/server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1049:11)
    at useSchemaOrg (file:///home/ririen/Projekty/Project/Website/.output/server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1053:21)
    at setup (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/app/server.mjs:3941:5)
    at _sfc_main.setup (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/app/server.mjs:4000:23)
    at callWithErrorHandling (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:1986:23)
    at setupStatefulComponent (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:7580:30)
    at setupComponent (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:7561:12)
    at renderComponentVNode (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:9930:17)
    at Object.ssrRenderComponent (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:10361:12)
    at default (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/app/server.mjs:3924:42)
[Vue warn]: Component  is missing template or render function.
[nuxt] [request error] [@vueuse/schema-org] Failed to find plugin, you may have forgotten to apply app.use(schemaOrg)
  at injectSchemaOrg (./server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1049:11)  
  at useSchemaOrg (./server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1053:21)  
  at setup (./server/chunks/app/server.mjs:3941:5)  
  at _sfc_main.setup (./server/chunks/app/server.mjs:4000:23)  
  at callWithErrorHandling (./server/chunks/index.mjs:1986:23)  
  at setupStatefulComponent (./server/chunks/index.mjs:7580:30)  
  at setupComponent (./server/chunks/index.mjs:7561:12)  
  at renderComponentVNode (./server/chunks/index.mjs:9930:17)  
  at Object.ssrRenderComponent (./server/chunks/index.mjs:10361:12)  
  at default (./server/chunks/app/server.mjs:3924:42)
Error: [@vueuse/schema-org] Failed to find plugin, you may have forgotten to apply app.use(schemaOrg)
    at injectSchemaOrg (file:///home/ririen/Projekty/Project/Website/.output/server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1049:11)
    at useSchemaOrg (file:///home/ririen/Projekty/Project/Website/.output/server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1053:21)
    at setup (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/app/server.mjs:3941:5)
    at _sfc_main.setup (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/app/server.mjs:4000:23)
    at callWithErrorHandling (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:1986:23)
    at setupStatefulComponent (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:7580:30)
    at setupComponent (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:7561:12)
    at renderComponentVNode (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:9930:17)
    at Object.ssrRenderComponent (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/index.mjs:10361:12)
    at default (file:///home/ririen/Projekty/Project/Website/.output/server/chunks/app/server.mjs:3924:42)
[Vue warn]: Component  is missing template or render function.
[nuxt] [request error] [@vueuse/schema-org] Failed to find plugin, you may have forgotten to apply app.use(schemaOrg)
  at injectSchemaOrg (./server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1049:11)  
  at useSchemaOrg (./server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1053:21)  
  at setup (./server/chunks/app/server.mjs:3941:5)  
  at _sfc_main.setup (./server/chunks/app/server.mjs:4000:23)  
  at callWithErrorHandling (./server/chunks/index.mjs:1986:23)  
  at setupStatefulComponent (./server/chunks/index.mjs:7580:30)  
  at setupComponent (./server/chunks/index.mjs:7561:12)  
  at renderComponentVNode (./server/chunks/index.mjs:9930:17)  
  at Object.ssrRenderComponent (./server/chunks/index.mjs:10361:12)  
  at default (./server/chunks/app/server.mjs:3924:42)

.output/server/chunks/app/server.mjs:3924

_push(serverRenderer.exports.ssrRenderComponent(_component_App, null, null, _parent));`

./server/chunks/index.mjs:10361

return renderComponentVNode(vue.createVNode(comp, props, children), parentComponent, slotScopeId);`

./server/node_modules/@vueuse/schema-org/dist/chunks/index.mjs:1046


function injectSchemaOrg() {
  const schemaOrg = inject(PROVIDE_KEY);
  if (!schemaOrg)
    throw new Error("[@vueuse/schema-org] Failed to find plugin, you may have forgotten to apply app.use(schemaOrg)");
  return schemaOrg;
}
oritwoen commented 2 years ago

@harlan-zw important note! The problem only occurs when the page is refreshed (it is loaded for the first time). It means that the schema in the app.vue file throws an error because it is global. Without schema in app.vue going to a subpage with a different schema using NuxtLink does not return an error but refreshing this page will.

leo91000 commented 2 years ago

This is a very strange bug that I also have. I made a reproduction on stackblitz, however, as odd as it seems, I had to run nuxt build twice to reproduce the bug. Very strange.

https://stackblitz.com/edit/github-n36kmg-mfimx6?file=app.vue

harlan-zw commented 2 years ago

Thanks for the reproduction @leo91000! Also thanks for the help debugging @0ri2N

I've pushed out a fix in release 0.6.0, let me know if you have any issues.

oritwoen commented 2 years ago

@harlan-zw Thanks. I checked and it looks like the build problem is gone.

However, the #3 reactivity problem has returned and the headline is not solved automatically inarticle with the title tag.

I will do a reproduction in my free time.

harlan-zw commented 2 years ago

Hey @0ri2N

Sorry to hear you're still having issues. As far as I can tell the reactivity issue as shown by the reproduction repo is working correctly (tested with version 0.6.2).

Please note that the SchemaOrgInspector will not work properly once the site is built, it's not meant to be shipped. The head tags should be accurate though.

If you're still having problems a separate issue with a new reproduction would be very much appreciated.