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

React+Tailwind CSS集成DaisyUI报错:Object.hasOwn is not a function

解决Tailwind CSS Intellisense报错Object.hasOwn is not a function的方案

方法1:指定插件使用本地Node版本

VS Code的Tailwind CSS Intellisense插件默认可能使用内置的旧版Node,即使本地升级了Node也不生效。手动指定插件使用本地Node:

  1. 打开VS Code设置(快捷键Ctrl+,/Cmd+,)
  2. 搜索Tailwind CSS: Node Path
  3. 填入你本地Node的完整路径:
    • Windows:C:\Program Files\nodejs\node.exe
    • macOS/Linux:/usr/local/bin/node
  4. 重启VS Code生效

方法2:降级daisyui版本

当前使用的daisyui@3.9.2可能依赖了使用Object.hasOwn的代码,而插件环境不支持。尝试降级到更早的稳定版本:

npm uninstall daisyui
npm install daisyui@3.8.1

方法3:添加Object.hasOwn兼容补丁

在你的Tailwind配置文件最顶部添加兼容代码,给旧环境补上这个方法:

// 兼容旧Node环境的Object.hasOwn
if (!Object.hasOwn) {
  Object.hasOwn = function(obj, prop) {
    return Object.prototype.hasOwnProperty.call(obj, prop);
  };
}

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  plugins: [require('daisyui')],
  daisyui: {
    themes: [
      {
        lightTheme: {
          primary: "#f4aa3a",
          secondary: "#f4f4a1",
          accent: "#1be885",
          neutral: "#272136",
          "base-100": "#ffffff",
          info: "#778ad4",
          success: "#23b893",
          warning: "#f79926",
          error: "#ea535a",
          body: {
            "background-color": "#e3e6e6",
          },
        },
      },
    ],
  },
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 03:53:14