vue3打包踩坑记录‘readFile‘ is not exported by __vite-browser-external, imported by node_modules/pdfjs-dist

这篇具有很好参考价值的文章主要介绍了vue3打包踩坑记录‘readFile‘ is not exported by __vite-browser-external, imported by node_modules/pdfjs-dist。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

打包报错如下

vue3打包踩坑记录‘readFile‘ is not exported by __vite-browser-external, imported by node_modules/pdfjs-dist,vue3,vue3

问题所在

因为vue3项目是用不了vue-pdf所以用了pdfjs-dist,开发环境pdf查看是没问题正常使用,只是在打包的时候就报错,应该是由于pdfjs-dist.js使用了fs,fs是nodejs环境下的工具库,所以vite才会报错。

处理办法

1、下载插件

cnpm install vite-plugin-commonjs-externals -D

2、vite.config.js配置

import commonjsExternals from 'vite-plugin-commonjs-externals';

plugins: [
		commonjsExternals({
		  externals: ['fs','canvas','zlib','http','https','url'] //这里
		}),
	],

这样轻松搞定打包报错问题。文章来源地址https://www.toymoban.com/news/detail-704452.html

到了这里,关于vue3打包踩坑记录‘readFile‘ is not exported by __vite-browser-external, imported by node_modules/pdfjs-dist的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 打包报错Error: ‘default‘ is not exported by node_modules/qs/lib/index.js

    问题描述: 当我们在使用rollup编译es6时,可能会遇到以下报错问题 解决方案: 安装@rollup/plugin-commonjs插件   最后,修改rollup.config.js文件中写入以下代码即可

    2024年02月16日
    浏览(37)
  • “hasInjectionContext“ is not exported by “node_modules/vue-demi/lib/index.mjs“, imported by “node_mo

    使用uniapp开发的微信小程序,技术栈使用的vue3+ts+uview-plus+pinia开发的,环境安装依赖没有问题,但是启动的时候报错: \\\"hasInjectionContext\\\" is not exported by \\\"node_modules/vue-demi/lib/index.mjs\\\", imported by \\\"node_modules/pinia/dist/pinia.mjs\\\". 11:36:19.397 at ../node_modules/pinia/dist/pinia.mjs:6:9 更换了好多个

    2024年02月04日
    浏览(37)
  • 安装pinia后编译项目报错“hasInjectionContext“ is not exported by “node_modules/vue-demi/lib/index.mjs“

    uniapp安装pinia时,编译项目报错\\\"hasInjectionContext\\\" is not exported by \\\"node_modules/vue-demi/lib/index.mjs\\\", imported by \\\"node_modules/pinia/dist/pinia.mjs\\\". 解决方法:将pinia的版本改成2.0.36,重新编译,就不报错了

    2024年04月14日
    浏览(48)
  • Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ‘./lib/tokenize‘ is not defined by “exports“

    今天在启动一个react项目的时候,我运行了这个命令: 项目启动过程中,控制台突然报了这个 错误 : 原因: 原来是我当时安装这个项目需要的依赖的时候,使用的node版本比较低,最近升级了一下node版本导致的。 解决办法: 第一种办法:将当前的node版本切回到当时安装项目

    2024年02月12日
    浏览(39)
  • Flutter 安装踩坑记录 HTTP host https://pub.dev/ is not reachable.

    Windows安装 flutter官网下载flutter sdk包 2.解压到C盘除去program file相关的目录(最好自己创建一个新的目录,因为放在program file等目录需要特殊的权限,会出现问题) Android 需要安装Android SDK ,同理苹果开发也需要对应的环境 安装ide工具(Android Studio ,visual studio code)都可以 运

    2024年02月08日
    浏览(33)
  • vue3的getCurrentInstance获取组件实例踩坑记录

    我们可以通过 getCurrentInstance这个函数来返回当前组件的实例对象,也就是当前vue这个实例对象 Vue2中,可以通过this来获取当前组件实例 ; Vue3中,在setup中无法通过this获取组件实例,console.log(this)打印出来的值是undefined 。 在Vue3中, getCurrentInstance() 可以用来获取当前组件实例

    2024年02月04日
    浏览(36)
  • Component is not found in path “components/xxx/xxx“ (using by “pages/xxx/xxx“) 问题记录

    相信做过小程序的都遇到过Component is not found in path “components/xxx/xxx“ (using by “pages/xxx/xxx“) 这个问题,一般情况的是引用路径有问题,检查代码路径改对就好了,又或者是 分包 影响的 先说一下我得使用场景,不一定适用于所有人,只是记录一下我遇到的 1.小程序是分包的

    2024年02月02日
    浏览(37)
  • uniapp+vue3打包问题记录

    **背景:**打包app出现问题,只显示底部导航的文字,其他一片空白 1. pages.json文件 :tabBar中的iconPath图标格式不支持svg,只支持:png, jpg, jpeg的格式,当图片改为.png的时候可以正常显示 2. 适配插件的影响 :使用了postcss-pxtorem插件,同时安装了lib-flexible插件,但因为lib-flexib

    2024年01月16日
    浏览(29)
  • vue3+vue-cli 报错 ‘defineProps‘ is not defined

      确保这些都存在,仍报错则需要修改node版本的 本人改到最新版就没什么问题了

    2024年02月12日
    浏览(46)
  • vue3 使用require报错:require is not defined

    1.报错原因 vue3使用vite打包 里面没有require方法, webpack 里面有这个方法 2.解决方案 使用import 代替 *注: 资源可使用import.meta.globEager(“…/*.png”) ; 动态引入,需要给 css 路径加括号 vite官网静态资源处理 new URL(url, import.meta.url) import.meta.url : ESM 的原生功能,会暴露当前模块的

    2024年02月07日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包