Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Support executing ESM schematics

未關閉
#22,786 7 則留言 61 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
angular, typescript
領域
cli

研究方向

首先追蹤編譯和執行自訂 schematics 的 Angular CLI 路徑,然後將其與所參照的 Angular loadEsmModule() workaround 以及連結的 schematics 範例進行比較。完成標準是 ESM schematics 可以在不出現回報的 CommonJS require() 錯誤的情況下執行,並且有針對該行為的測試涵蓋。

由索引模型根據 Issue 內容生成。

描述

area: @angular-devkit/schematics feature feature: under consideration

🚀 Feature request

Support schematics written in ES Modules. Currently only CommonJS schematics are supported.

Command (mark with an x)
  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc
  • other: compiling custom schematics
Description

Currently custom (and official) schematics can execute only CommonJS code, but not ES Modules. This is problematic when you want to import an ES Module in your custom schematics, for example HtmlParser from @angular/compiler (which since ng13 is shipped only as ESM).

Problems with not supporting ESM:

The following error started to occur for our custom schematics in runtime, since we upgraded from ng12 to 13:
require() of ES Module <path-to-the-repo>/node_modules/@angular/compiler/fesm2015/compiler.mjs not supported. Instead change the require of <path-to-the-repo>/node_modules/@angular/compiler/fesm2015/compiler.mjs to a dynamic import() which is available in all CommonJS modules.

But the advised change of the static @angular/compiler to a dynamic import is cumbersome due to various reasons:

  • it unnecessarily changes the our synchronous code to asynchronous code
  • it induces passing down the compilerModule (result of await import(@angular/compiler)) as an argument down to all helper functions (example in angular repo)
  • it requires a hacky workaround ticking the Typescript compiler so to avoid compiling the dynamic import() into the require() call - for more see the workaround function loadEsmModule() in angular repo . Btw. this function is not exported in public API, so we need to copy-paste it to our repo.
Describe the solution you'd like

Support executing ESM schematics .

Describe alternatives you've considered

Change the import of ESM to dynamic imports in our schematics code and deal with all its cumbersome consequences (described above).

主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
17 小時 25 分鐘
30 天內合併 PR
183

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。