With ESLint 10 and typescript-eslint's projectService, eslint.config.js and scripts/*.mjs fail with "was not found by the project service" — how do you fix each?
answer
- no tsconfig includes the file
- include it, allow it, or untype it
- allowDefaultProject: no double-star globs
- eight default-project files at most
- disableTypeChecked in a later files object
basics
~20 sNo tsconfig.json includes those files, so the project service cannot type them. Add them to tsconfig.json's include, list a few in projectService.allowDefaultProject, or turn typed linting off for them with a files-scoped disableTypeChecked object; ignore files you never lint.
solid answer
~50 sWith `projectService`, typescript-eslint types each file through its nearest `tsconfig.json`; a file that tsconfig does not include gets a parsing error saying it `was not found by the project service`. There are four fixes. **Include** the files in `tsconfig.json` when you want them typed (JavaScript files also need `allowJs` there). Use **`projectService.allowDefaultProject`** for a few stray files such as `eslint.config.js`: globs resolve from `tsconfigRootDir`, `**` is rejected, a listed file must not also be in its tsconfig, each one costs extra time, and more than eight matches is an error by default. Add **`tseslint.configs.disableTypeChecked`** in a later object scoped with `files`, such as `scripts/*.mjs`, to switch typed parsing and typed rules off there. Or **ignore** files you never lint. In ESLint 10 that scoping is a flat-config object with `files` and `extends`; eslintrc `overrides` are gone.
code
javascript · 21 lines// eslint.config.js (package.json has "type": "module")
import js from '@eslint/js';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
export default defineConfig(
{
files: ['**/*.{js,mjs,ts}'],
extends: [js.configs.recommended, tseslint.configs.recommendedTypeChecked],
languageOptions: {
parserOptions: {
projectService: { allowDefaultProject: ['eslint.config.js'] },
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ['scripts/*.mjs'],
extends: [tseslint.configs.disableTypeChecked],
},
);go deeper
Recognise the message: a file outside every tsconfig.json cannot be typed. Know that it is a configuration gap, not a bug in the file itself.
Lay out the four fixes and what each costs: include the file, allow it as a default-project file, turn typed linting off for it, or ignore it.
Choose per file and defend it: allowDefaultProject only for a few root files given its limits and per-file cost, disableTypeChecked placed after the typed preset, and other plugins' typed rules handled too.
Set a rule for the repository: every file is either owned by a tsconfig, deliberately untyped, or ignored, so new scripts do not quietly add per-file default-project cost.
## Why the error appears With `parserOptions.projectService`, typescript-eslint builds type information for each linted file from the `tsconfig.json` **nearest** to it. A typical root `tsconfig.json` has `"include": ["src"]`, so two kinds of file fall outside every project: - **Root config files** such as `eslint.config.js`, which the typed config object matches through a broad `files` pattern like `**/*.{js,mjs,ts}`. - **Loose scripts** such as `scripts/*.mjs`. A tsconfig also leaves `.js` and `.mjs` files out unless `allowJs` or `checkJs` is enabled. For each such file, the parser reports a **parsing error** saying the file `was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject`. Nothing else in the run is wrong; typed linting has simply been asked for types it cannot compute. ## The four fixes | Fix | Use it when | Cost or limit | |---|---|---| | Add the file to `tsconfig.json`'s `include` | You want it typed and it belongs to the project | JavaScript needs `allowJs`; the compiler now includes it too | | `projectService.allowDefaultProject` | A handful of root-level files | No `**`; not also in a tsconfig; a separate program per file; eight files by default | | `tseslint.configs.disableTypeChecked` for a `files` glob | Untyped rules are enough for those files | Typed rules off there; other plugins' typed rules need disabling by hand | | An `ignores` pattern | You never want the file linted | Nothing is linted at all | ## `allowDefaultProject` in detail `allowDefaultProject` (default `[]`) lists globs of files that may be typed with a **default project** although no tsconfig includes them. It exists for files like `eslint.config.js`, and typescript-eslint asks you to use it sparingly: - Globs resolve relative to `tsconfigRootDir`. - `**` is **not allowed** in its globs. - A matched file must **not** also be included by its nearest `tsconfig.json`. - Each matched file gets its own TypeScript program, a non-trivial cost **per file**. - By default it may match at most **eight** files; beyond that, linting fails with an error that many default-project files slow linting down. The option that raises the cap is called `maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING`, and the name is the advice. - The compiler options for those files come from `projectService.defaultProject`, which defaults to `'tsconfig.json'`. ## `disableTypeChecked` in detail `tseslint.configs.disableTypeChecked` is a single configuration object. It sets the parser's `program` to `null` and `project` and `projectService` to `false`, and it turns off every typed rule typescript-eslint ships. Two rules govern its use: 1. It must come **after** the object that enables typed linting, because when several objects match a file, later ones override earlier ones. 2. Type-aware rules from **other plugins** stay on; turn them off in the same object. ## The ESLint 10 config The configuration example shows all three fixes together: `eslint.config.js` typed through the default project, `scripts/*.mjs` linted without types, and everything else typed through `tsconfig.json`. ESLint 10 reads only flat config; the eslintrc format was removed in 10.0.0. typescript-eslint's documentation still carries "Legacy Config" tabs whose `overrides` arrays scope `disable-type-checked` to `*.js` files; in ESLint 10, that scoping is a configuration object with `files`. The documented shape is ESLint's `defineConfig()` with `extends` inside an object, available since ESLint 9.22.0. typescript-eslint 8 deprecates its own `tseslint.config()` helper in favour of `defineConfig()`. ## Reading the example file by file - `src/refill/submit.ts` matches the first object; the project service finds `tsconfig.json` (which includes `src`) and types it. - `eslint.config.js` matches the first object too; no tsconfig includes it, so it is typed through the default project, which `allowDefaultProject` permits. - `scripts/notify.mjs` matches both objects; the later one wins for the settings it touches, so parsing runs without type information and the typed rules are off, while the untyped rules from the first object still apply. - A file in `dist/` would be typed like any other `.js` file, and fail, unless an `ignores` pattern keeps it out of the run. ## Choosing per file 1. **Application code a tsconfig should own** goes into that tsconfig's `include`. 2. **One or two root config files** go into `allowDefaultProject`. 3. **Scripts where untyped rules suffice** get a later `disableTypeChecked` object. 4. **Generated output** such as `dist/` or `coverage/` goes into `ignores`, and is never linted.
- Why not just put **/*.mjs in allowDefaultProject?`**` is rejected in `allowDefaultProject` globs, and the option is capped at eight matched files by default because each file builds its own TypeScript program. A recursive glob is exactly the overuse those limits exist to stop: include the files in a `tsconfig.json` or turn typed linting off for them instead.
- After adding disableTypeChecked for scripts/*.mjs, a rule from another plugin still asks for type information there. Why?`disableTypeChecked` turns off only typescript-eslint's own typed rules and its parser's type options. A type-aware rule from another plugin stays enabled, so turn it off in the same `files`-scoped object, or use a disabling config that plugin provides.
- allowDefaultProject accepts recursive ** globs like any files pattern.
- Listing a file in allowDefaultProject is harmless even when tsconfig.json already includes it.
- disableTypeChecked must come before the type-checked preset in the config array.
- The legacy overrides block still works in ESLint 10, so no files-scoped flat-config object is needed.
- The project service reads tsconfig.eslint.json, so adding the files there fixes the error.
Assumes ESLint 10 with typescript-eslint 8.71.1: eslintrc and its overrides blocks were removed in ESLint 10.0.0, so files-scoped flat-config objects (defineConfig with extends, since 9.22.0) carry disableTypeChecked.