vue-pdf-viewer / starter-vpv-nuxt-ts

Vue PDF Viewer Starter Toolkit with Nuxt
https://www.vue-pdf-viewer.dev/
0 stars 1 forks source link

Promise.withResolvers is not a function #3

Closed edanweis closed 1 month ago

edanweis commented 1 month ago

I have tried using with Nuxt3 SSR creating a new register-components.ts with "nuxt": "^3.12.3"

import { addComponent, defineNuxtModule } from "@nuxt/kit";
export default defineNuxtModule({
  setup() {
    addComponent({
      name: "MyPDFViewer",
      export: "VPdfViewer",
      filePath: "@vue-pdf-viewer/viewer",
    });
  },
});

Installed with pnpm. Used override "pdfjs-dist": "4.4.168". Added

transpile: [
      (ctx) => ctx.isServer ? 'pdfjs-dist': false,
      (ctx) => ctx.isServer ? '@vue-pdf-viewer/viewer': false
    ]

But get error

ERROR  Promise.withResolvers is not a function

  at node_modules/.pnpm/pdfjs-dist@4.6.82/node_modules/pdfjs-dist/build/pdf.mjs:5744:35
  at ViteNodeRunner.runModule (node_modules/.pnpm/vite-node@1.6.0_@types+node@20.14.11_sass@1.77.7_terser@5.31.3/node_modules/vite-node/dist/client.mjs:362:11)
  at ViteNodeRunner.directRequest (node_modules/.pnpm/vite-node@1.6.0_@types+node@20.14.11_sass@1.77.7_terser@5.31.3/node_modules/vite-node/dist/client.mjs:346:16)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async ViteNodeRunner.cachedRequest (node_modules/.pnpm/vite-node@1.6.0_@types+node@20.14.11_sass@1.77.7_terser@5.31.3/node_modules/vite-node/dist/client.mjs:189:14)
  at async ViteNodeRunner.dependencyRequest (node_modules/.pnpm/vite-node@1.6.0_@types+node@20.14.11_sass@1.77.7_terser@5.31.3/node_modules/vite-node/dist/client.mjs:233:12)
  at async node_modules/.pnpm/@vue-pdf-viewer+viewer@1.2.0_pdfjs-dist@4.6.82_vite@5.3.3_@types+node@20.14.11_sass@1.77.7_te_bkttvcxbydyexkslis3mv7nnq4/node_modules/@vue-pdf-viewer/viewer/dist/index.js:2:31
  at async ViteNodeRunner.runModule (node_modules/.pnpm/vite-node@1.6.0_@types+node@20.14.11_sass@1.77.7_terser@5.31.3/node_modules/vite-node/dist/client.mjs:362:5)
  at async ViteNodeRunner.directRequest (node_modules/.pnpm/vite-node@1.6.0_@types+node@20.14.11_sass@1.77.7_terser@5.31.3/node_modules/vite-node/dist/client.mjs:346:5)
  at async ViteNodeRunner.cachedRequest (node_modules/.pnpm/vite-node@1.6.0_@types+node@20.14.11_sass@1.77.7_terser@5.31.3/node_modules/vite-node/dist/client.mjs:189:14)
<ClientOnly>
    <MyPDFViewer :src="props.panel?.data?.output.url" />
</ClientOnly>
kittisakLS commented 1 month ago

addComponent

Referring to Components · Nuxt Kit, the VPV doesn't run on the server-side. So, I think you may need to add mode: 'client' when using addComponent to register the component.

addComponent({
   name: "MyPDFViewer",
   export: "VPdfViewer",
   filePath: "@vue-pdf-viewer/viewer",
   mode: 'client'
});

Hope this helps! Let me know if it doesn't.