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

React Vite项目导入Flowbite遇require未定义问题求助

解决React Vite项目中Flowbite导入的require/import问题
  • 先确认Flowbite已正确安装,未安装的话执行对应命令:

    npm install flowbite
    # 或使用yarn
    yarn add flowbite
    
  • 修改你的tailwind.config.js,采用ES模块静态导入方式引入Flowbite插件:

    /** @type {import('tailwindcss').Config} */
    import flowbite from 'flowbite/plugin'
    
    export default {
      content: ["./src/**/*.{js,jsx,ts,tsx}", "./node_modules/flowbite/**/*.js"],
      theme: {
        extend: {},
      },
      plugins: [flowbite],
    };
    
  • 最后在项目入口文件(如main.jsx或main.tsx)中导入Flowbite核心脚本:

    import 'flowbite';
    

之前的require报错是因为Vite默认使用ES模块规范,不支持CommonJS的require语法;若你之前用import没生效,大概率是用了动态导入这类错误写法,改用上述静态导入即可解决问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 07:10:55