{"record":{"id":"db08cf0b90dd6260","repo":"cypress-io/cypress","slug":"no-tsconfig-json-found-ts-loader-needs-a-tsconfig","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"TsConfigNotFoundError","httpStatus":null,"severity":"error","filePath":"npm/webpack-batteries-included-preprocessor/index.ts","lineNumber":90,"sourceCode":"    if (!rule.use || !Array.isArray(rule.use)) return false\n\n    return rule.use.some((use: any) => {\n      return use.loader && use.loader.match(/(^|[^a-zA-Z])ts-loader([^a-zA-Z]|$)/)\n    })\n  })\n}\n\nconst addTypeScriptConfig = (file: { filePath: string }, options: {\n  typescript?: string | boolean\n  webpackOptions?: any\n}) => {\n  // returns null if tsconfig cannot be found in the path/parent hierarchy\n  const configFile = getTsConfig.getTsconfig(file.filePath)\n\n  if (!configFile && typescriptExtensionRegex.test(file.filePath)) {\n    debug('no user tsconfig.json found. Throwing TsConfigNotFoundError')\n    // @see https://github.com/cypress-io/cypress/issues/18938\n    throw new TsConfigNotFoundError()\n  }\n\n  debug(`found user tsconfig.json at ${configFile?.path} with compilerOptions: ${JSON.stringify(configFile?.config?.compilerOptions)}`)\n\n  let typeScriptPath: string | boolean | undefined | null = null\n\n  try {\n    if (options.typescript === true) {\n      const configFileDirectory = path.dirname(configFile?.path ?? '')\n\n      // attempt to resolve typescript from the user's tsconfig.json file / project directory\n      typeScriptPath = require.resolve('typescript', { paths: [configFileDirectory] })\n      options.typescript = typeScriptPath\n    } else {\n      typeScriptPath = options.typescript\n    }\n\n    debug(`using typescript found at ${typeScriptPath}`)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/npm/webpack-batteries-included-preprocessor/index.ts#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: ts spec, no tsconfig\n// cypress/e2e/spec.cy.ts exists, no tsconfig.json anywhere\n// after: create tsconfig.json\n{ \"compilerOptions\": { \"target\": \"es2020\", \"module\": \"commonjs\", \"types\": [\"cypress\"] } }\n// or disable ts-loader path\npreprocessor({ typescript: false, ... })","handlingStrategy":"validation","validationCode":"import getTsConfig from 'get-tsconfig'\nfunction ensureTsConfig(filePath: string) {\n  if (/\\.m?tsx?$/.test(filePath) && !getTsConfig.getTsconfig(filePath)) {\n    throw new Error('Create tsconfig.json before bundling TS specs')\n  }\n}","typeGuard":"const isTsFile = (p: string): boolean => /\\.m?tsx?$/.test(p)","tryCatchPattern":"try { preprocessor(options) } catch (e) { if (e.name === 'TsConfigNotFoundError') { /* create tsconfig or set typescript:false */ } else throw e }","preventionTips":["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."],"tags":["webpack","typescript","preprocessor","tsconfig","config"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}