You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过CDN以ESM方式导入Picmo Popup picker时出现语法错误求助

解决Picmo Popup Picker浏览器ESM导入错误的思路
  • 问题根源:你用的是ESM的import语法,但引入的是UMD格式的文件,两种模块规范不兼容——UMD不会通过export暴露createPopup,所以触发了找不到导出成员的错误。

  • 核心解决步骤:

    1. 替换为ESM版本的Popup Picker文件
      把原来的UMD链接换成ESM入口文件,比如用:
      import { createPopup } from 'https://unpkg.com/@picmo/popup-picker@latest/dist/esm/index.js'
      
      或者用unpkg的?module参数自动获取ESM版本:
      import { createPopup } from 'https://unpkg.com/@picmo/popup-picker@latest?module'
      
    2. 确保基础Picmo模块也用ESM版本
      既然你之前导入createPicker正常,确认它也是ESM版本,比如:
      import { createPicker } from 'https://unpkg.com/picmo@latest/dist/esm/index.js'
      
    3. 验证使用流程
      示例代码参考:
      // 导入模块
      import { createPicker } from 'https://unpkg.com/picmo@latest/dist/esm/index.js';
      import { createPopup } from 'https://unpkg.com/@picmo/popup-picker@latest/dist/esm/index.js';
      
      // 获取触发按钮
      const triggerBtn = document.getElementById('emoji-btn');
      
      // 创建基础选择器
      const emojiPicker = createPicker({
        showSearch: true,
        categories: ['smileys', 'people', 'animals']
      });
      
      // 创建弹窗选择器
      const popupPicker = createPopup(emojiPicker, {
        triggerElement: triggerBtn,
        position: 'bottom-end'
      });
      
      // 绑定触发事件
      triggerBtn.addEventListener('click', () => {
        popupPicker.toggle();
      });
      
  • 额外提示:如果遇到依赖加载问题,检查unpkg上的文件路径是否正确,也可以指定具体版本号代替@latest,避免版本更新带来的兼容性问题。

内容的提问来源于stack exchange,提问作者vnihoul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 20:15:46