cypress-io/cypress · error · TsConfigNotFoundError
No tsconfig.json found. ts-loader needs a tsconfig.json file
Error message
No tsconfig.json found. ts-loader needs a tsconfig.json file to work. Please add one to your project in either the root or the cypress directory.
What it means
Thrown as TsConfigNotFoundError by @cypress/webpack-batteries-included-preprocessor when addTypeScriptConfig cannot find a tsconfig.json (get-tsconfig returns null walking up from the spec's filePath) AND the file is a TypeScript file (matches /.m?tsx?$/). ts-loader requires a tsconfig.json to compile TS, so the preprocessor refuses to bundle the spec rather than silently emitting untyped JS.
Source
Thrown at npm/webpack-batteries-included-preprocessor/index.ts:90
if (!rule.use || !Array.isArray(rule.use)) return false
return rule.use.some((use: any) => {
return use.loader && use.loader.match(/(^|[^a-zA-Z])ts-loader([^a-zA-Z]|$)/)
})
})
}
const addTypeScriptConfig = (file: { filePath: string }, options: {
typescript?: string | boolean
webpackOptions?: any
}) => {
// returns null if tsconfig cannot be found in the path/parent hierarchy
const configFile = getTsConfig.getTsconfig(file.filePath)
if (!configFile && typescriptExtensionRegex.test(file.filePath)) {
debug('no user tsconfig.json found. Throwing TsConfigNotFoundError')
// @see https://github.com/cypress-io/cypress/issues/18938
throw new TsConfigNotFoundError()
}
debug(`found user tsconfig.json at ${configFile?.path} with compilerOptions: ${JSON.stringify(configFile?.config?.compilerOptions)}`)
let typeScriptPath: string | boolean | undefined | null = null
try {
if (options.typescript === true) {
const configFileDirectory = path.dirname(configFile?.path ?? '')
// attempt to resolve typescript from the user's tsconfig.json file / project directory
typeScriptPath = require.resolve('typescript', { paths: [configFileDirectory] })
options.typescript = typeScriptPath
} else {
typeScriptPath = options.typescript
}
debug(`using typescript found at ${typeScriptPath}`)View on GitHub (pinned to 0d85fdc912)
Solutions
- Add a tsconfig.json at the project root (or cypress/ directory): `npx tsc --init`.
- If you do not want TS compilation via ts-loader, configure the preprocessor with `typescript: false` to use the Babel TS path instead.
- Point get-tsconfig at an explicit tsconfig by placing one in the spec's directory hierarchy.
- Verify the tsconfig.json filename spelling and that it is not git-ignored/uncommitted.
Example fix
// before: ts spec, no tsconfig
// cypress/e2e/spec.cy.ts exists, no tsconfig.json anywhere
// after: create tsconfig.json
{ "compilerOptions": { "target": "es2020", "module": "commonjs", "types": ["cypress"] } }
// or disable ts-loader path
preprocessor({ typescript: false, ... }) Defensive patterns
Strategy: validation
Validate before calling
import getTsConfig from 'get-tsconfig'
function ensureTsConfig(filePath: string) {
if (/\.m?tsx?$/.test(filePath) && !getTsConfig.getTsconfig(filePath)) {
throw new Error('Create tsconfig.json before bundling TS specs')
}
} Type guard
const isTsFile = (p: string): boolean => /\.m?tsx?$/.test(p)
Try / catch
try { preprocessor(options) } catch (e) { if (e.name === 'TsConfigNotFoundError') { /* create tsconfig or set typescript:false */ } else throw e } Prevention
- Add a tsconfig.json at the project root whenever using TS specs.
- If you don't want ts-loader, configure the preprocessor with typescript:false.
- Run `npx tsc --init` as part of project scaffolding.
When it happens
Trigger: Preprocessing a .ts/.tsx/.mts/.cts spec file when no tsconfig.json exists from the spec's directory up to the filesystem root. Triggered when webpack-batteries-included-preprocessor's defaultFile handler invokes addTypeScriptConfig for that file.
Common situations: A Cypress project using the batteries-included preprocessor with TS specs but no tsconfig.json (e.g. a JS project where someone added a .ts spec), or a tsconfig.json placed outside the search path. Note: setting `typescript: false` in preprocessor options bypasses ts-loader entirely and avoids this error.
Related errors
- No typescript installable was found. ts-loader needs a versi
- Unexpected framework ${(devServerConfig as any).framework},
- Unable to automerge with the config file
- Could not read '${path}'.
- Failed to parse "${this.path}" as JSON AST Object. ${printPa
AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12).
Data as JSON: /api/errors/db08cf0b90dd6260.
Report an issue: GitHub.