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

Tailwind 3.3.2配置报错:module is not defined问题求助

解决Tailwind配置文件中module is not defined错误

这个错误并非代码本身的问题,而是编辑器/语法检查工具的环境识别偏差导致的,常见原因和解决方法如下:

  • 编辑器环境配置问题
    你的编辑器可能将tailwind.config.js识别为浏览器环境代码(而非Node.js环境),而module是Node.js CommonJS模块系统的全局变量,浏览器环境中不存在。解决方法:

    • 在配置文件顶部添加注释,明确告知检查工具这是Node.js环境:
      /* eslint-env node */
      /** @type {import('tailwindcss').Config} */
      module.exports = {
        content: ["./src/**/*.{html,js}"],
        theme: {
          extend: {},
        },
        plugins: [],
      }
      
    • 如果使用VS Code,可以在项目的.vscode/settings.json中添加配置,强制识别Node.js环境:
      {
        "javascript.implicitProjectConfig.checkJs": true,
        "typescript.tsdk": "node_modules/typescript/lib"
      }
      
  • 项目模块系统不匹配
    如果你的项目package.json中配置了"type": "module"(启用ES模块系统),那么CommonJS的module.exports语法会不兼容,此时需要将配置文件改为ES模块格式:

    /** @type {import('tailwindcss').Config} */
    export default {
      content: ["./src/**/*.{html,js}"],
      theme: {
        extend: {},
      },
      plugins: [],
    }
    
  • ESLint配置缺失Node环境
    若使用ESLint做代码检查,需确保配置中启用了Node环境:
    在.eslintrc.js或.eslintrc.json中添加:

    {
      "env": {
        "node": true
      }
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 00:22:04