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

  1. Add a tsconfig.json at the project root (or cypress/ directory): `npx tsc --init`.
  2. If you do not want TS compilation via ts-loader, configure the preprocessor with `typescript: false` to use the Babel TS path instead.
  3. Point get-tsconfig at an explicit tsconfig by placing one in the spec's directory hierarchy.
  4. 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

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


AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12). Data as JSON: /api/errors/db08cf0b90dd6260. Report an issue: GitHub.