Vite ES6方式引入dayjs报错

根据官方文档使用es6方式引入dajs后报错import dayjs from 'dayjs' my-app.ts:73 One or more components failed to load SyntaxError: The requested module '../node_modules/dayjs/dayjs.min.js' does not provide an export named 'default'

问题描述

Vite中使用ES6模式引入dayjs
import dayjs from 'dayjs'
报错
my-app.ts:73 One or more components failed to load SyntaxError: The requested module '../node_modules/dayjs/dayjs.min.js' does not provide an export named 'default'
尝试切换方式后
import * as dayjs from 'dayjs'
新的报错
One or more components failed to load TypeError: Cannot set property 'dayjs' of undefined

解决方案

import dayjs from 'dayjs/esm/index.js'
  • 1.本站主要是为了记录工作、学习中遇到的问题,可能由于本人技术有限,有些不正确的地方,仅供参考。
  • 2.本站中会转载我认为有用的博客文章,添加一些外链网站地址,但这些博客文章、论坛和网站上的内容和我没有关系,不代表我的意见,请网友自己多注意辨别。
  • 3.本站中转载文章会写明来源(点击下方链接按钮即可),感谢原作者的辛苦写作,如果有异议,及时联系我处理,谢谢!
  • 4.欢迎指出有问题的地方,我会尽快修正,谢谢!

系统由 Nginx + Next.js + React + Node + TailWindCss 驱动

沪ICP备20021316号