naive-ui
naive-ui copied to clipboard
UMD方式引入时报错,ReferenceError: naive is not defined
描述错误
在使用较低,但不是很低版本的浏览器,并且用UMD方式引入时,浏览器不兼容 ReferenceError: naive is not defined
复现步骤
1.使用较低版本chrome,例如:https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win_x64/800850/ 2.用上述版本浏览器访问官方文档的UMD演示页面:https://jsbin.com/mutewosewu/edit?html,console,output 3.js会有报错,页面也无法正常渲染 4.访问官方文档的非UMD方式导入的二维码组件页面是正常的:https://www.naiveui.com/zh-CN/os-theme/components/qr-code
最小复现链接
https://jsbin.com/mutewosewu/edit?html,console,output
系统信息
chrome:87.0.4242.0
naiveUI:2.38.1
vue:latest
使用的包管理器
pnpm
验证
ReferenceError: naive is not defined
是 umd 的 build.target 没有设置或为 esnext 引起的
https://github.com/tusen-ai/naive-ui/blob/d1d306cfc3d5b51c32c2cf526978ac25c97e6177/rollup.config.js#L31-L40
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks#browser_compatibility
根据 Static_initialization_blocks 的兼容性 chrome94,这意味着 naive-ui 的 umd 链接只能在 chrome94 以上工作
ui 库的 umd 这种能独立直接使用的格式实际上应该设置较低的转译目标,并且应该自包含 polyfill
是 umd 的 build.target 没有设置或为 esnext 引起的
https://github.com/tusen-ai/naive-ui/blob/d1d306cfc3d5b51c32c2cf526978ac25c97e6177/rollup.config.js#L31-L40
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks#browser_compatibility
根据 Static_initialization_blocks 的兼容性 chrome94,这意味着 naive-ui 的 umd 链接只能在 chrome94 以上工作
感谢答复!
This issue does not have any recent activity. If you are still experiencing similar problems, open a new error, including a minimal copy of the problem