You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix TypeScript helper loading and import resolution (#5313)
* Initial plan
* Add TypeScript transpilation support for custom helpers
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
* Remove accidentally committed .husky.bak directory
* Fix TypeScript import resolution for extensionless imports
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>
* Fix TypeScript import detection for files with dots in name
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>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
thrownewError(`Failed to load TypeScript helper ${importPath}: ${tsError.message}. Make sure 'typescript' package is installed.`)
418
+
}
419
+
}
420
+
401
421
// check if the new syntax export default HelperName is used and loads the Helper, otherwise loads the module that used old syntax export = HelperName.
402
422
try{
403
423
// Try dynamic import for both CommonJS and ESM modules
404
-
constmod=awaitimport(moduleName)
424
+
constmod=awaitimport(importPath)
405
425
if(!mod&&!mod.default){
406
426
thrownewError(`Helper module '${moduleName}' was not found. Make sure you have installed the package correctly.`)
0 commit comments