Skip to content

Conversation

@paescuj
Copy link
Contributor

@paescuj paescuj commented Oct 27, 2025

Fixes #798

Dynamically load typescript via require, so that it only needs to be installed on user-side when type checking is enabled.
Tested in ESM and CJS context ✅

Notes:

  • This issue hasn't really surfaced as pnpm (and possibly other package managers) automatically installs peer dependencies.
  • We need to rely on require instead of dynamic import because ESLint rules can't be async.
  • As an alternative, we could declare typescript as a prod dependency ourselves or bundle it. However, since typescript is necessary on user-side for type checking anyway, this seems to be the most appropriate solution.

@veritem veritem merged commit 2ff2dcd into vitest-dev:main Oct 27, 2025
5 checks passed
@paescuj paescuj deleted the fix/dynamically-require-typescript branch October 27, 2025 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ERR_MODULE_NOT_FOUND]: Cannot find package 'typescript in js project

2 participants