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

Turborepo Monorepo中ESM TypeScript的ESLint配置异常问题

Turborepo Monorepo下ESLint配置加载失败问题

我在Turborepo monorepo环境中,尝试从package文件夹扩展加载两份ESLint配置文件,但在database包中使用ESM语法的TypeScript代码执行lint时,出现错误:Parsing error: The keyword 'export' is reserved。

运行命令 eslint --print-config index.ts 后得到空配置,说明配置未正确加载:

{
  "env": {},
  "globals": {},
  "parser": null,
  "parserOptions": {},
  "plugins": [],
  "rules": {},
  "settings": {},
  "ignorePatterns": []
}

两份ESLint配置文件

基础配置文件(如base.js)

module.exports = {
    extends: ["eslint:recommended", "plugin:import/recommended", "prettier"],
    rules: {
        "prefer-const": "warn",
        "no-console": "warn",
        "no-duplicate-imports": "error",
        "spaced-comment": ["error", "always", { markers: ["/", "!", "?"] }],
        "arrow-body-style": ["warn", "as-needed"],
        "import/no-cycle": "error",
        "import/prefer-default-export": "off",
        "import/extensions": [
            "error",
            "ignorePackages",
            { js: "never", jsx: "never", ts: "never", tsx: "never" },
        ],
    },
    settings: {
        "import/resolver": {
            node: true,
        },
    },
    env: {
        node: true,
        es6: true,
    },
    ignorePatterns: ["node_modules"],
};

TypeScript专属配置文件(如typescript.js)

const { resolve } = require("node:path");

const project = resolve(process.cwd(), "tsconfig.json");

module.exports = {
    parser: "@typescript-eslint/parser",
    parserOptions: {
        project,
    },
    extends: [
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/recommended-requiring-type-checking",
        "plugin:import/typescript",
    ],
    rules: {
        "@typescript-eslint/no-empty-function": "off",
        "@typescript-eslint/no-namespace": "off",
        "@typescript-eslint/no-misused-promises": [
            "error",
            {
                checksVoidReturn: {
                    attributes: false,
                },
            },
        ],
    },
    settings: {
        "import/resolver": {
            typescript: {
                project,
            },
        },
    },
};

相关包文件

database/package.json

{
    "name": "database",
    "version": "1.0.0",
    "exports": "./index.ts",
    "types": "./index.ts",
    "scripts": {
        "db:generate": "prisma generate",
        "db:push": "prisma db push --skip-generate",
        "format": "prisma format",
        "lint": "eslint . --ext .ts",
        "lint:ts": "tsc --noEmit",
        "studio": "prisma studio"
    },
    "dependencies": {
        "@prisma/client": "^5.3.1"
    },
    "devDependencies": {
        "@types/node": "^20.6.3",
        "eslint-config-custom": "workspace:*",
        "prisma": "^5.3.1",
        "tsconfig": "workspace:*"
    }
}

database/tsconfig.json

{
    "$schema": "https://json.schemastore.org/tsconfig",
    "display": "Default",
    "compilerOptions": {
        "composite": false,
        "declaration": true,
        "declarationMap": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "inlineSources": false,
        "isolatedModules": true,
        "moduleResolution": "Node16",
        "module": "Node16",
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "preserveWatchOutput": true,
        "skipLibCheck": true,
        "strict": true
    },
    "exclude": ["node_modules"]
}

eslint-config-custom/package.json

{
    "name": "eslint-config-custom",
    "version": "1.0.0",
    "main": "index.js",
    "license": "MIT",
    "scripts": {
        "format": "prettier --write ./*.js"
    },
    "dependencies": {
        "@typescript-eslint/eslint-plugin": "^6.7.2",
        "@typescript-eslint/parser": "^6.7.2",
        "eslint": "^8.50.0",
        "eslint-config-next": "^13.4.19",
        "eslint-config-prettier": "^9.0.0",
        "eslint-config-turbo": "^1.10.14",
        "eslint-import-resolver-typescript": "^3.6.1",
        "eslint-plugin-import": "^2.28.1",
        "eslint-plugin-jsx-a11y": "^6.7.1",
        "eslint-plugin-react": "7.33.2",
        "eslint-plugin-react-hooks": "^4.6.0",
        "eslint-plugin-tailwindcss": "^3.13.0"
    },
    "devDependencies": {
        "typescript": "^5.2.2"
    },
    "publishConfig": {
        "access": "public"
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 11:24:50