How I built a test that walks the shipped import graph: the missing module that bricked Ankita 2.7.0
说明与用途
构建了一个测试,遍历已打包的导入图,确保所有相对导入的模块都包含在 ASAR 中,防止运行时模块未找到错误。
问题
After shipping Ankita v2.7.0, the desktop app failed to start due to an ERR_MODULE_NOT_FOUND for a missing module in the ASAR package.
结果
The test prevented future packaging regressions by detecting missing modules before release, ensuring the ASAR contains all required files.
工作流
- Load electron‑builder.yml and build a file matcher from app‑builder‑lib.
- Enumerate all .mjs/.js/.cjs/.mts/.json files under source trees that contribute shipped code.
- Filter files using the matcher to get the exact set that will be packaged.
- Scan each packaged file for literal relative import statements using regexes.
- Resolve each import specifier against the importing file’s directory. If the target exists on disk but is not in the packaged set, record it as missing.
- Assert that the missing map is empty; if not, fail the test with the list of missing modules and importers.
证据
The main process died with ERR_MODULE_NOT_FOUND for desktop/chatgpt-companion/sign-in.mjs.
The packaging config listed desktop/electron/**/* and desktop/browser-helper/**/*, but not desktop/chatgpt-companion/**/*.
The new test lives in test/desktop/chatgpt-package.test.mjs, named every local module imported by packaged sources ships inside the ASAR file set.
- 记录日期: 2026-10-26T11:26:08.618Z