fix(init): emit ESM-compatible tsconfig for TypeScript projects#5596
Merged
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5594
Problem
Running
npx codeceptjs initand selecting TypeScript support emits atsconfig.jsonthat contradicts the rest of the setupinitproduces.initalready installstsx,typescript,@types/nodeand writesrequire: ['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 —initinstallstsx, notts-node, andlib/utils/loaderCheck.jsexplicitly marks ts-node as "not recommended.""module": "commonjs"is wrong for the ESM 4.x design and makes editors flag the extensionless imports shown indocs/typescript.md.Fix
Generate a tsconfig that matches the tsx/ESM setup
initalready configures:ts-nodeblock.module: "commonjs"→"ESNext".moduleResolution: "bundler"so extensionless imports (import { admin } from './fixtures', exactly as the docs show) resolve the waytsx/esbuild actually resolve them.NodeNextwould force.jsextensions and contradict the docs.target/libes2018→ES2022, 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:
tsxdoesn'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.jspasses (no test pins the tsconfig contents).🤖 Generated with Claude Code