so, in another instance I have packages/eslint-config, do I import this config alone…
- User
so, in another instance I have packages/eslint-config, do I import this config alone into my other apps without needing to import the eslint packages and plugins if I am not modifying the existing eslint-config right?
- Assistant
You've hit on a common point of confusion in monorepos, and it's a great question!
The short answer is: Yes, you still need to install ESLint itself and any plugins/parsers that are referenced by your
packages/eslint-configwithin your monorepo's root.Here's why and how:
Why you still need to install them
-
ESLint is the "Runner": Your
packages/eslint-configsimply exports a configuration object (rules, plugins to use, parsers). It doesn't contain the ESLint executable or the logic to run linting. For ESLint to run, theeslintpackage itself must be present and discoverable. -
Plugins and Parsers are separate packages: When your
eslint-configsaysplugins: ['@typescript-eslint', 'react']orparser: '@typescript-eslint/parser', ESLint expects to find these specific npm packages in thenode_moduleswhere it's being run. Your config package simply references them; it doesn't include their code. They are separate dependencies.
Best approach for a Bun Monorepo
The best practice for a monorepo is to install
eslintand all the common plugins/parsers youreslint-configuses at the root level of your monorepo. This allows all your workspaces to share these dependencies, leveraging Bun's hoisting capabilities.1. Install ESLint and Plugins at the Monorepo Root:
In your monorepo's root
package.json, add all the ESLint-related packages asdevDependencies:// monorepo-root/package.json { "name": "my-monorepo", "private": true, "workspaces": [ "app/*", "packages/*" ], "devDependencies": { "eslint": "^8.x.x", // The core ESLint package "prettier": "^3.x.x", // If you integrate Prettier "@typescript-eslint/eslint-plugin": "^6.x.x", // For TypeScript rules "@typescript-eslint/parser": "^6.x.x", // For parsing TypeScript "eslint-config-prettier": "^9.x.x", // Disables ESLint rules that conflict with Prettier "eslint-plugin-prettier": "^5.x.x", // Runs Prettier as an ESLint rule "eslint-plugin-react": "^7.x.x", // For React specific rules (if app/web uses React) "eslint-plugin-react-hooks": "^4.x.x", // For React Hooks rules "eslint-plugin-jsx-a11y": "^6.x.x", // For accessibility rules // ... any other plugins your config uses "typescript": "^5.x.x" // TypeScript itself, as discussed previously } }Then run
bun installin the root. Bun will hoist these dependencies to the rootnode_modules.2. Your
packages/eslint-config:This package will contain your shared ESLint rules. Its
package.jsonshould declare the ESLint packages it uses aspeerDependencies. This informs users (or in this case, your other workspaces) that they need to provide these dependencies themselves.// packages/eslint-config/package.json { "name": "@my-org/eslint-config", // Use a scope for clarity if you wish "version": "1.0.0", "main": "index.js", "private": true, // Since it's internal to your monorepo "peerDependencies": { "eslint": ">=8", "@typescript-eslint/eslint-plugin": ">=6", "@typescript-eslint/parser": ">=6", "eslint-plugin-react": ">=7", "eslint-plugin-react-hooks": ">=4", "eslint-plugin-jsx-a11y": ">=6", "eslint-config-prettier": ">=9", "eslint-plugin-prettier": ">=5", "prettier": ">=3" // List all packages your config *uses* here }, "devDependencies": { // These are only for the eslint-config package itself to run tests or lint itself // You can copy them from the root devDependencies here if you want to test the config independently. // Otherwise, for monorepo internal usage, you might not strictly need them here if all testing is done via the root. "eslint": "^8.x.x", "@typescript-eslint/eslint-plugin": "^6.x.x", // ... etc. } }And your
index.js(or.eslintrc.js) inpackages/eslint-config:// packages/eslint-config/index.js (or .eslintrc.js) module.exports = { extends: [ "eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react/recommended", "plugin:react-hooks/recommended", "plugin:jsx-a11y/recommended", "prettier", // Must be last to turn off conflicting rules ], parser: "@typescript-eslint/parser", plugins: ["@typescript-eslint", "react", "react-hooks", "jsx-a11y", "prettier"], env: { browser: true, node: true, es2022: true, }, settings: { react: { version: "detect", // Automatically detect React version }, }, rules: { "prettier/prettier": "error", // Your custom rules here "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], // ... }, // Ensure rules are applied to specific file types overrides: [ { files: ["*.ts", "*.tsx"], parserOptions: { project: ["./tsconfig.json"], // Or your specific tsconfig file if different }, }, ], };3. Reference the Config in your Apps/Packages:
In
app/web,app/api,packages/api-client, etc., you need to:-
Add the
eslint-configpackage as adevDependency:// app/web/package.json { "name": "app-web", // ... "devDependencies": { "@my-org/eslint-config": "workspace:^1.0.0" // Reference your internal package } }Run
bun installinapp/web(or at the root again). -
Create a
.eslintrc.jsfile:// app/web/.eslintrc.js module.exports = { root: true, // Stops ESLint from looking for configs in parent directories extends: [ "@my-org/eslint-config", // This is how you reference your shared config // Add any workspace-specific configs or overrides here ], // Add workspace-specific settings or rules overrides rules: { // e.g., if app/web has specific React rules } };If you don't use a scope for your
eslint-configpackage, it would beextends: ["eslint-config"]ifpackages/eslint-config/package.jsonhasname: "eslint-config".
Summary of Benefits
- Single Source of Truth: All ESLint versions and primary plugins are managed in one place (root
package.json). - Reduced Duplication: Bun hoists dependencies, meaning fewer
node_modulesfolders and less disk space. - Consistency: All your workspaces automatically use the same ESLint configuration and versions of the tools.
- Simplicity: Workspace
package.jsonfiles are cleaner, only listing their unique dependencies and the shared config.
This setup gives you a very robust and maintainable linting strategy for your Bun monorepo.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.