FranckFreiburger / vue-pdf

vue.js pdf viewer
MIT License
2.21k stars 519 forks source link

vue-pdf不能兼容vite吗 报错require is not defined #367

Open stanwu-1 opened 2 years ago

stanwu-1 commented 2 years ago
sam0817 commented 2 years ago

same issue:

vue-router.esm-bundler.js:3302 ReferenceError: require is not defined
    at vuePdfNoSss.vue:8:22

looks broken @ this require:

if ( process.env.VUE_ENV !== 'server' ) {

        var pdfjsWrapper = require('./pdfjsWrapper.js').default;
        var PDFJS = require('pdfjs-dist/es5/build/pdf.js');
meiqiangyu commented 1 year ago

https://www.npmjs.com/package/dy-vite-vue-pdf 这个可以用,兼容了vite打包

chenweigh commented 1 year ago

遇见了同样的错误, vue3, vite3

chenweigh commented 1 year ago

vue3+vite 推荐使用:https://github.com/hrynko/vue-pdf-embed 亲测好使 使用方式:

import VuePdfEmbed from 'vue-pdf-embed'
//vite中本地pdf文件,不需要 loader,直接import即可使用。
//vue-pdf-embed 也支持远端pdf
import testPdf from './1.pdf'
import { reactive } from 'vue'
const state = reactive({ pdf: testPdf })
<template>
<vue-pdf-embed :source="state.pdf" />
</template>
yang1978u commented 4 months ago

vue3+vite 推荐使用:https://github.com/hrynko/vue-pdf-embed 亲测好使 使用方式:

import VuePdfEmbed from 'vue-pdf-embed'
//vite中本地pdf文件,不需要 loader,直接import即可使用。
//vue-pdf-embed 也支持远端pdf
import testPdf from './1.pdf'
import { reactive } from 'vue'
const state = reactive({ pdf: testPdf })
<template>
<vue-pdf-embed :source="state.pdf" />
</template>

看起来可以使用

LonelyRookie commented 6 days ago

我也遇到的同样的问题,vue3+vite Uncaught ReferenceError: require is not defined (anonymous function) vuePdfNoSss.vue:8