vue-pdf: Component is not processed by Webpack ( Unexpected token < )
When loaded as the following:
<template>
<pdf v-bind:src="_document" />
</template>
<script>
import pdf from 'vue-pdf';
export default {
components: {
pdf
},
_document: {
data: "..."
}
}
</script>
I get the following error:
[vue-router] Failed to resolve async component default: SyntaxError: Unexpected token <
[vue-router] uncaught error during route navigation:
/Users/betacar/Code/JavaScript/project/node_modules/vue-pdf/src/pdf.vue:1
(function (exports, require, module, __filename, __dirname) { <template>
^
SyntaxError: Unexpected token <
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at r (/Users/betacar/Code/JavaScript/project/node_modules/vue-server-renderer/build.js:5812:16)
at Object.<anonymous> (server-bundle.js:1980:18)
at __webpack_require__ (server-bundle.js:27:30)
at Object.47 (0.server-bundle.js:35:66)
at __webpack_require__ (server-bundle.js:27:30)
at Object.44 (0.server-bundle.js:9:3)
at __webpack_require__ (server-bundle.js:27:30)
Am I missing something?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 9
- Comments: 39 (10 by maintainers)
I had this issue today, using the nuxt/pwa template
nuxt version: 1.4.1 vue-pdf: 3.3.1
For me, this worked: (but I get the
[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.)vue-pdfis delivered without bundle (nodist/directory), then you need to tell your build system (webpack or any other) to includevue-pdfin their compilation process and eventually to transpilevue-pdf.webpack:
webpack-node-externals, you must addvue-pdfin thewhitelist: []\.jswebpack rule does not exclude thenode_modules/vue-pdfdirectorynuxt:
This is still happening. And all of the duplicate issues seem to be closed. Is there any help out there to resolve this?
Using webpack (Laravel-mix) and version “vue-pdf”: “^4.3.0”,
This problem still occurs when testing with Jest in my nuxt2 environment as well I’ve tried all of the solutions supposed above but none of them works.
If you use Nuxt this may help:
I created a plugin pdf.js
added it to nuxt.config.js
and in the template:
import pdf from 'vue-pdf/src/vuePdfNoSss 'work for meThread bump. This still doesn’t work with vue-SSR.