先安装的:
npm install pdfjs-dist --save
报错按提示安装的:
npm install --save babel-polyfill
也按网上说的把: main.js的第一行给了:
import "babel-polyfill"
项目启动报错:
ERROR Failed to compile with 1 error 16:24:33
error in ./node_modules/pdfjs-dist/build/pdf.js
Module parse failed: Unexpected token (405:14)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| }
| function _isValidProtocol(url) {
> switch (url?.protocol) {
| case "http:":
| case "https:":
@ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/ImageMask/index.vue?vue&type=script&lang=js& 37:0-35 38:0-5 38:94-99 174:24-29
代码中这样使用的:
import { PDFJS } from 'pdfjs-dist'
PDFJS.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${PDFJS.version}/pdf.worker.js`
看报错应该是不支持可选链操作符语法导致的语法错误
安装
配置
在babel.config.js中添加: