Problem
When creating a new TypeScript extension with yo code, the generated project installs @types/mocha in devDependencies but does not add "mocha" to the "types" field in tsconfig.json.
This causes immediate TypeScript errors in the scaffolded test file:
Cannot find name 'suite'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/mocha and then add 'mocha' to the types field in your tsconfig.
Cannot find name 'test'. Do you need to install type definitions for a test runner? ...
Related Issue
This is closely related to #575 (“TypeScript cannot find Node globals with default VSCode tsconfig”). Both issues stem from the same TypeScript 6.0 change to the default "types" behavior.
Root Cause
TypeScript 6.0 changed the default behavior of the "types" compiler option:
- Before TS 6: Omitting
"types" automatically included all packages under node_modules/@types.
- TS 6+: The default is now an empty array (
"types": []). Packages must be listed explicitly.
The current yo code template was written for the old behavior and was never updated for this breaking change.
Expected Behavior
The generated tsconfig.json (or the relevant test tsconfig) should include:
"compilerOptions": {
...
"types": ["mocha", "node"]
}
(or at least "mocha").
Steps to Reproduce
- Run
yo code and choose a TypeScript extension.
- Open the generated project in VS Code.
- Observe red errors on
suite and test in src/test/extension.test.ts.
Suggested Fix
Update the TypeScript templates in generator-code so that the generated tsconfig.json explicitly lists the required types (mocha and usually node).
Problem
When creating a new TypeScript extension with
yo code, the generated project installs@types/mochaindevDependenciesbut does not add"mocha"to the"types"field intsconfig.json.This causes immediate TypeScript errors in the scaffolded test file:
Cannot find name 'suite'. Do you need to install type definitions for a test runner? Try
npm i --save-dev @types/mochaand then add 'mocha' to the types field in your tsconfig.Cannot find name 'test'. Do you need to install type definitions for a test runner? ...
Related Issue
This is closely related to #575 (“TypeScript cannot find Node globals with default VSCode tsconfig”). Both issues stem from the same TypeScript 6.0 change to the default
"types"behavior.Root Cause
TypeScript 6.0 changed the default behavior of the
"types"compiler option:"types"automatically included all packages undernode_modules/@types."types": []). Packages must be listed explicitly.The current
yo codetemplate was written for the old behavior and was never updated for this breaking change.Expected Behavior
The generated
tsconfig.json(or the relevant testtsconfig) should include:"compilerOptions": {
...
"types": ["mocha", "node"]
}
(or at least
"mocha").Steps to Reproduce
yo codeand choose a TypeScript extension.suiteandtestinsrc/test/extension.test.ts.Suggested Fix
Update the TypeScript templates in
generator-codeso that the generatedtsconfig.jsonexplicitly lists the required types (mochaand usuallynode).