-
-
Notifications
You must be signed in to change notification settings - Fork 751
Fix TypeScript helper loading and import resolution #5313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
|
@copilot when custom helper got another import, I got this error when I add .js to ./abstract.helper, tests are running successfully.
|
Automatically add .js extension to relative imports that don't have a standard module extension. This fixes the ERR_MODULE_NOT_FOUND error when TypeScript files import other files without specifying an extension (e.g., import from "./abstract.helper" instead of "./abstract.helper.js"). The transpiler now: - Detects imports without standard extensions (.js, .mjs, .cjs, .json, .node) - Adds .js extension automatically for ESM compatibility - Handles both transpiled TypeScript files (rewrites to .temp.mjs) and regular JS files Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
... Fixed in commit 37878c1. The transpiler now automatically adds import { AbstractHelper } from "./abstract.helper";Without needing to add
All 31 container tests pass including new test for this scenario. |
|
@copilot investigate, handle more scenarios and fix issues, here is one of the issues
it leads to issue: |
Fixed issue where TypeScript files with dots in their names (e.g., abstract.helper.ts) were not being detected and transpiled when imported without extension. The problem was that path.extname() would consider the last dot as a file extension. Now the transpiler: - Checks if an import has a standard module extension (.js, .mjs, .cjs, .json, .node) - If not, tries adding .ts extension to find and transpile TypeScript files - This correctly handles files like abstract.helper.ts, material.component.helper.ts, etc. Added test case to verify this scenario works correctly. Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
Fixed in commit 6adc892. The issue was that The fix now checks for standard module extensions (.js, .mjs, .cjs, .json, .node) and if the import doesn't have one, it tries adding Now both files are correctly transpiled:
And the import is rewritten to: All 32 container tests pass including new test for this scenario. |
Motivation/Description of the PR
Node.js cannot import
.tsfiles directly. When users specified TypeScript helpers viarequirein config, CodeceptJS failed withERR_UNKNOWN_FILE_EXTENSION. Additionally, when TypeScript helpers imported other TypeScript files without extensions, they would fail withERR_MODULE_NOT_FOUND. A further issue occurred when TypeScript files had dots in their names (e.g.,abstract.helper.ts), where the transpiler failed to detect them as TypeScript files to transpile.Example config that now works:
Example helper with extensionless imports that now works:
Changes:
Modified
requireHelperFromModuleinlib/container.jsto detect.tsextensions and transpile using existingtranspileTypeScriptutility before import. Cleanup of temporary files occurs on both success and error paths.Modified
transpileTypeScriptinlib/utils/typescript.jsto automatically add.jsextension to relative imports that don't have standard module extensions (.js, .mjs, .cjs, .json, .node). This ensures ESM compatibility and eliminates the need for users to manually add.jsextensions to their TypeScript imports.Fixed TypeScript file detection in dependency discovery to properly identify files with dots in their names (e.g.,
abstract.helper.ts,material.component.helper.ts). The transpiler now checks for standard module extensions instead of treating any dot as a file extension, ensuring all TypeScript dependencies are correctly detected and transpiled.These changes match the pattern already implemented in
loadSupportObjectfor TypeScript support files and provide a seamless experience for TypeScript users with any naming convention.Applicable helpers:
Applicable plugins:
Type of change
Checklist:
npm run docs)npm run lint)npm test)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.