Vue项目中未定义模块
P粉235202573
P粉235202573 2023-11-17 12:38:53

我刚刚通过运行 npm init vue@latest 创建了一个新的 Vue 应用程序,如官方文档中指定的那样。然后我尝试按照 Vue 和 Vite 网站上的指南将 Tailwind 添加到我的应用程序中。但是,当打开文件 tailwind.config.js 时,我注意到 ESLint 告诉我 module 未定义,并且 module.exports 语法不起作用。

这是为什么?我该如何解决?

编辑:Vue 创建的默认 .eslintrc.cjs 文件如下所示:

/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
  root: true,
  extends: [
    "plugin:vue/vue3-essential",
    "eslint:recommended",
    "@vue/eslint-config-prettier",
  ],
  parserOptions: {
    ecmaVersion: "latest",
  },
};


P粉235202573
P粉235202573

全部回复(2)
P粉333186285

考虑使用

  • .eslintrc.cjs
    …
      overrides: [
        {
          files: ["{vue,vite}.config.*"],
          env: {
            node: true,
          },
        },
      ],
    

以及仅为这些文件设置 compilerOptions.types: ["node"] TS 选项。



它可能是这样的:

  • .eslintrc.cjs

    /* eslint-env node */
    require("@rushstack/eslint-patch/modern-module-resolution");
    
    module.exports = {
      root: true,
      extends: [
        "plugin:vue/vue3-essential",
        "eslint:recommended",
        "@vue/eslint-config-typescript",
        "@vue/eslint-config-prettier",
      ],
      overrides: [
        {
          files: ["cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}"],
          extends: ["plugin:cypress/recommended"],
        },
        {
          files: ["{vue,vite}.config.*"],
          env: {
            node: true,
          },
        },
      ],
      parserOptions: {
        ecmaVersion: "latest",
      },
    };
  • tsconfig.config.json

    {
      "extends": "@vue/tsconfig/tsconfig.node.json",
      "include": ["vue.config.*", "vite.config.*", "vitest.config.*", "cypress.config.*", "playwright.config.*"],
      "compilerOptions": {
        "composite": true,
        "types": ["node"]
      }
    }
    
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!