当前位置: 首页 > article >正文

解决vue使用pdfdist-mergeofd插件时报错polyfills

在这里插入图片描述

pdfdist-mergeofd

该插件主要是为了解决pdf-js和ofd-js共同使用时产生的依赖冲突问题,具体可看这位博主的文章同时使用ofdjs和pdfjs遇到的问题,和解决方法——懒加载

首先看下报错信息

ERROR in ./node_modules/.pnpm/pdfdist-mergeofd@2.2.228_webpack@5.95.0/node_modules/pdfdist-mergeofd/build/pdf.js 19510:14-28 Module not found: Error: Can't resolve 'url' in 'xxx\node_modules.pnpm\pdfdist-mergeofd@2.2.228_webpack@5.95.0\node_modules\pdfdist-mergeofd\build'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }' - install 'url' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "url": false } @ ./node_modules/.pnpm/babel-loader@8.4.1_@babel+core@7.25.8_webpack@5.95.0/node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/.pnpm/@vue+cli-service@5.0.8_prettier@2.8.8_sass-loader@12.6.0_vue-template-compiler@2.6.14_vue@2.6.14/node_modules/@vue/cli-service/lib/config/vue-loader-v15-resolve-compat/vue-loader.js??vue-loader-options!./src/views/signature/sign/index.vue?vue&type=script&lang=js 21:12-39 @ ./src/views/signature/sign/index.vue?vue&type=script&lang=js 1:0-437 1:453-456 1:458-892 1:458-892 @ ./src/views/signature/sign/index.vue 2:0-56 3:0-51 3:0-51 10:2-8 @ ./src/views/index.js 228:11-84 @ ./src/views/remoteIndex.js 1:0-43 @ container entry ./views[0]

webpack compiled with 1 error

报错分析

这个错误是因为 Webpack 5 不再默认包含 Node.js 核心模块的 polyfills,导致 url 模块无法解析。为了解决这个问题,需要在 vue.config.js 中配置 resolve.fallback 来提供 url 模块的 polyfill。

解决办法

先在命令行输入npm install url安装url模块,然后修改vue.config.js文件,添加resolve.rollback

//vue.config.js中添加resolve.rollback
module.exports = {
  configureWebpack: {
    resolve: {
    	//这个配置项允许在 Webpack 中为缺失的模块提供一个回退路径。
        fallback: {
          //这指定了 url 模块的路径。
          url: require.resolve('url/'),
          //这指定了 path 模块的路径
          path: require.resolve('path-browserify'),
          //如果不需要 fs 模块,可以设置为 false。
          fs: false,
          http: false,
          https: false,
          zlib: false
        }
      }
  }
};

http://www.kler.cn/a/369082.html

相关文章:

  • OpenCV系列教程六:信用卡数字识别、人脸检测、车牌/答题卡识别、OCR
  • 在Postgresql中对空间数据进行表分区的实践
  • 软考:中间件
  • linux指令笔记
  • 海洋生物图像分割系统:算法改进策略
  • 嵌入式刷题(day21)
  • VMware各版本下载的镜像站(含windows和linux)
  • ptp4l协议_配置文件
  • 【JIT/极态云】技术文档--函数设计
  • java :String 类
  • ReactOS系统中平衡二叉树,在一个空间中寻找与给定地址范围重合或部分重合的(已分配)区间
  • Python 实现日期计算与日历格式化输出(万年历)
  • Qt 窗口可见性 之 close函数和hide函数
  • [Go实战]:HTTP请求转发
  • 电商平台店铺运营:巧用 API 接口的策略之道
  • jemalloc替换标准库 malloc等函数的三种方式
  • 宿舍管理新篇章:基于Spring Boot的系统开发
  • 验证俩套加密算法是否互通
  • [思考记录]做事别忘最初目的
  • 安全见闻(7)-上(网络安全热门证书介绍及备考指南)
  • 理解OAuth2与用户账户与授权UAA的关系
  • thinkadmin,点击列表导出excel
  • [NOIP2015 普及组] 求和
  • Go语言基础教程:函数
  • H5的Canvas绘图——使用fabricjs绘制一个可多选的随机9宫格
  • 微信小程序 - 深 / 浅拷贝实现方法,微信小程序深拷贝与浅拷贝,函数方法封装直接调用使用,深拷贝cloneDeep和浅拷贝clone(深复制和浅复制)