File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import ActorFactory from './actor.js'
1919import output from './output.js'
2020import { emptyFolder } from './utils.js'
2121import { initCodeceptGlobals } from './globals.js'
22- import { validateTypeScriptSetup } from './utils/loaderCheck.js'
22+ import { validateTypeScriptSetup , getTSNodeESMWarning } from './utils/loaderCheck.js'
2323import recorder from './recorder.js'
2424
2525import storeListener from './listener/store.js'
@@ -270,6 +270,12 @@ class Codecept {
270270 process . exit ( 1 )
271271 }
272272
273+ // Show warning if ts-node/esm is being used
274+ const tsWarning = getTSNodeESMWarning ( this . requiringModules || [ ] )
275+ if ( tsWarning ) {
276+ output . print ( output . colors . yellow ( tsWarning ) )
277+ }
278+
273279 // Ensure translations are loaded for Gherkin features
274280 try {
275281 const { loadTranslations } = await import ( './mocha/gherkin.js' )
Original file line number Diff line number Diff line change @@ -106,6 +106,34 @@ Note: TypeScript config files (codecept.conf.ts) and helpers are automatically
106106`
107107}
108108
109+ /**
110+ * Get warning message if ts-node/esm is being used
111+ * @param {string[] } requiredModules - Array of required modules from config
112+ * @returns {string|null } Warning message or null
113+ */
114+ export function getTSNodeESMWarning ( requiredModules = [ ] ) {
115+ if ( ! requiredModules . includes ( 'ts-node/esm' ) ) {
116+ return null
117+ }
118+
119+ return `
120+ ⚠️ Warning: ts-node/esm with "module": "esnext" requires explicit file extensions in all imports.
121+
122+ This is a known limitation. Use tsx/cjs instead to write imports without extensions.
123+
124+ Examples:
125+
126+ ❌ Incorrect (will fail):
127+ import loginPage from "./pages/Login";
128+
129+ ✅ Correct (must include .ts extension):
130+ import loginPage from "./pages/Login.ts";
131+
132+ 📚 Documentation: https://codecept.io/typescript
133+
134+ `
135+ }
136+
109137/**
110138 * Check if user is trying to run TypeScript tests without proper loader
111139 * @param {string[] } testFiles - Array of test file paths
You can’t perform that action at this time.
0 commit comments