Comments (4)
Hi @spokospace , I just tried on a fresh installation of Vue and there doesn't seem to be any problem with the builds. If you're using a modern bundler you can import the component like import { VuePdf, createLoadingTask } from 'vue3-pdfjs';
If you still wish to use the esm folder you'll need to add a declaration to your shims file like declare module 'vue3-pdfjs/esm';
from vue3-pdfjs.
Hello. Okay, yes, thanks! I configured it and run on development mode correctly, but still have issue with production.
I'm trying to connect this with vite-ssg (inside vitesse starter template).
I tried with:
import { VuePdf, createLoadingTask } from 'vue3-pdfjs/cjs/index.js'
but then I have error 'window is not defined':
[vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
(node:7) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at eval (/home/projects/github-ijnjm5/node_modules/pdfjs-dist/legacy/web/pdf_viewer.js:2141:3)
at new Promise (<anonymous>)
at Array.Object.defineProperty.value (/home/projects/github-ijnjm5/node_modules/pdfjs-dist/legacy/web/pdf_viewer.js:2140:24)
or:
[vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
/www/catalog/node_modules/.pnpm/[email protected]/node_modules/pdfjs-dist/legacy/web/pdf_viewer.js:2224
window.requestAnimationFrame(resolve);
^
ReferenceError: window is not defined
I have the rest of the site based on vitesse, so I really care not to change that. If I manage to configure it with pdf, I will let you know.
from vue3-pdfjs.
I tried it with async load and checking if window is not undefined:
const pdfSrc = ref<VuePdfPropsType['src']>(props.pdfPath)
const numOfPages = ref(0)
onMounted(async() => {
if (typeof window !== 'undefined') {
const vue3Pdfjs = await import('vue3-pdfjs')
const VuePdf = vue3Pdfjs.VuePdf
const createLoadingTask = vue3Pdfjs.createLoadingTask
const loadingTask = createLoadingTask(pdfSrc.value)
loadingTask.promise.then((pdf: PDFDocumentProxy) => {
numOfPages.value = pdf.numPages
})
}
})
and also with globally import:
import type { UserModule } from '~/types'
export const install: UserModule = ({ isClient, app }) => {
if (isClient)
import('vue3-pdfjs').then(({ VuePdf, createLoadingTask }) => {
app.use(VuePdf)
}).catch(e => {
console.error('vue3-pdfjs error', e)
})
}
but then I have error:
index-19f89c12.js?v=c8422c1c:3 Uncaught (in promise) SyntaxError: The requested module '/node_modules/.pnpm/[email protected]/node_modules/pdfjs-dist/legacy/build/pdf.worker.entry.js?v=c8422c1c' does not provide an export named 'default'
There is any way to fix this issue with pdf worker?
or:
SyntaxError: Invalid or unexpected token
vue3-pdfjs error SyntaxError: Invalid or unexpected token
Ok, last one error is because no CORS settings, after put correct CORS there is no unexpected token and it's working on production with vite-ssg but not always.
Sometimes, before refresh in Firefox I have:
vue3-pdfjs error SyntaxError: identifier starts immediately after numeric literal
from vue3-pdfjs.
Hi @spokospace , I just tried on a fresh installation of Vue and there doesn't seem to be any problem with the builds. If you're using a modern bundler you can import the component like
import { VuePdf, createLoadingTask } from 'vue3-pdfjs';
If you still wish to use the esm folder you'll need to add a declaration to your shims file like
declare module 'vue3-pdfjs/esm';
run for vite, have erro: Cannot read properties of undefined (reading 'DISABLE')
from vue3-pdfjs.
Related Issues (16)
- Multiple page pdfs initiate multiple requests HOT 4
- Error when running with vite HOT 3
- This plugin support typescript HOT 1
- First rendering problem on mobile side HOT 2
- vue3-pdfjs/esm缺少svg导致报错 HOT 1
- 还在维护吗?发票pdf缺少文字 HOT 3
- memory leak HOT 1
- withCredentials support HOT 2
- Cannot read properties of null (reading 'headersReady') HOT 1
- vite:css-post error
- Annotation do not work (Vue 3, Vite 5)
- 支付宝环境报错,只能显示一页
- run serve problem about 'canvas' HOT 1
- Question regarding loading pages dynamically HOT 2
- Wrong scale on print mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue3-pdfjs.