cypress-io/cypress · error · TypeScriptNotFoundError

No typescript installable was found. ts-loader needs a versi

Error message

No typescript installable was found. ts-loader needs a version of typescript to work properly. Please install typescript in your project's package.json.

What it means

Thrown as TypeScriptNotFoundError by @cypress/webpack-batteries-included-preprocessor when require.resolve('typescript', { paths: [configFileDirectory] }) fails. ts-loader needs the `typescript` package present to type-check and emit; the preprocessor tries to resolve typescript from the user's tsconfig directory (when options.typescript === true) or from the explicit path (options.typescript as string), and throws if neither resolves.

Source

Thrown at npm/webpack-batteries-included-preprocessor/index.ts:112

  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}`)
  } catch {
    debug('no user typescript found. Throwing TypeScriptNotFoundError')

    throw new TypeScriptNotFoundError()
  }
  // shortcut if we know we've already added typescript support
  // @ts-expect-error - not typed intentionally
  if (options.__typescriptSupportAdded) return options

  const webpackOptions = options.webpackOptions
  const rules = webpackOptions.module && webpackOptions.module.rules

  // if there are no rules defined or it's not an array, we can't add to them
  if (!rules || !Array.isArray(rules)) return options

  // if we find ts-loader configured, don't add it again
  if (hasTsLoader(rules)) {
    debug('ts-loader already configured, not adding again')

    return options
  }

View on GitHub (pinned to 0d85fdc912)

Solutions

  1. Install TypeScript in the project: `npm install -D typescript`.
  2. If using a monorepo, ensure typescript is resolvable from the directory of your tsconfig.json (hoist it or add to that workspace).
  3. If options.typescript is set to a path, verify the path exists and points at a valid typescript module.
  4. Reinstall dependencies if you recently changed Node majors (native modules / hoisting shifts).

Example fix

// before: tsconfig.json present but typescript not installed
// after
npm install -D typescript@5
Defensive patterns

Strategy: validation

Validate before calling

import { createRequire } from 'module'
function ensureTypescriptResolvable(dir: string) {
  try { createRequire(import.meta.url).resolve('typescript', { paths: [dir] }) }
  catch { throw new Error('Install typescript: npm i -D typescript') }
}

Type guard

const isTypescriptResolvable = (dir: string): boolean => { try { createRequire(import.meta.url).resolve('typescript', { paths: [dir] }); return true } catch { return false } }

Try / catch

try { addTypeScriptConfig(file, options) } catch (e) { if (e.name === 'TypeScriptNotFoundError') { /* npm i -D typescript, retry */ } else throw e }

Prevention

When it happens

Trigger: addTypeScriptConfig reaches the require.resolve('typescript', ...) branch (because options.typescript is true or a path string) and Node throws MODULE_NOT_FOUND. Occurs when TypeScript is not installed in the project, is installed only as a transitive dep not resolvable from the tsconfig dir, or options.typescript points at a nonexistent path.

Common situations: A TS Cypress project where `typescript` was never added to package.json devDependencies, a monorepo where typescript lives in the root but the spec's tsconfig dir cannot resolve it, or a stale npm install.

Related errors


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