Skip to content

fix(init): emit ESM-compatible tsconfig for TypeScript projects#5596

Merged
DavertMik merged 1 commit into
4.xfrom
fix/init-tsconfig-esm
Jun 1, 2026
Merged

fix(init): emit ESM-compatible tsconfig for TypeScript projects#5596
DavertMik merged 1 commit into
4.xfrom
fix/init-tsconfig-esm

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

@DavertMik DavertMik commented Jun 1, 2026

Fixes #5594

Problem

Running npx codeceptjs init and selecting TypeScript support emits a tsconfig.json that contradicts the rest of the setup init produces. init already installs tsx, typescript, @types/node and writes require: ['tsx/cjs'] for an ESM project — but the generated tsconfig is a leftover from the 3.x/ts-node era:

{
  "ts-node": { "files": true },     // ts-node is never installed by init
  "compilerOptions": {
    "module": "commonjs",           // wrong for an ESM ("type": "module") project
    ...
  }
}
  • "ts-node": { files: true } does nothing — init installs tsx, not ts-node, and lib/utils/loaderCheck.js explicitly marks ts-node as "not recommended."
  • "module": "commonjs" is wrong for the ESM 4.x design and makes editors flag the extensionless imports shown in docs/typescript.md.

Fix

Generate a tsconfig that matches the tsx/ESM setup init already configures:

  • Drop the ts-node block.
  • module: "commonjs""ESNext".
  • Add moduleResolution: "bundler" so extensionless imports (import { admin } from './fixtures', exactly as the docs show) resolve the way tsx/esbuild actually resolve them. NodeNext would force .js extensions and contradict the docs.
  • Bump target/lib es2018ES2022, in line with the repo's own tsconfig.
{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022", "DOM"],
    "esModuleInterop": true,
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strictNullChecks": false,
    "types": ["codeceptjs", "node"],
    "declaration": true,
    "skipLibCheck": true
  },
  "exclude": ["node_modules"]
}

Note: tsx doesn't require a tsconfig.json at all — this file exists purely for editor IntelliSense and type checking, which is why it should reflect the real ESM/tsx setup.

Testing

test/runner/init_test.js passes (no test pins the tsconfig contents).

🤖 Generated with Claude Code

`codecept init` installs tsx and sets `require: ['tsx/cjs']`, but the
generated tsconfig.json still carried the legacy ts-node setup:

- a `"ts-node": { files: true }` block, though ts-node is never installed
  and is marked "not recommended" in loaderCheck.js
- `"module": "commonjs"`, wrong for an ESM ("type": "module") project

Generate a tsconfig that matches the tsx/ESM setup init already configures:
drop the ts-node block, use `module: ESNext` with `moduleResolution: bundler`
(so extensionless imports resolve as tsx/docs expect), and bump target/lib
to ES2022.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@DavertMik DavertMik merged commit d18924b into 4.x Jun 1, 2026
12 checks passed
@DavertMik DavertMik deleted the fix/init-tsconfig-esm branch June 1, 2026 15:24
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.

CodeceptJS v4 initializes tsconfig for cjs and ts-node

1 participant