You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决编译阶段未包含package.json导致的可执行文件启动错误?

错误解析与排查补充信息

错误信息

Error: Cannot inject the dependency "modCompilerService" at position #3 of "PreAkiModLoader" constructor. Reason:
    File 'C:\**\project\package.json' was not included into executable at compilation stage. Please recompile adding it as asset or script.
    at C:\snapshot\project\node_modules\tsyringe\dist\cjs\dependency-container.js:324:23
    at Array.map (<anonymous>)
    at C:\snapshot\project\node_modules\tsyringe\dist\cjs\dependency-container.js:295:38
    at InternalDependencyContainer.construct (C:\snapshot\project\node_modules\tsyringe\dist\cjs\dependency-container.js:297:11)
    at InternalDependencyContainer.resolveRegistration (C:\snapshot\project\node_modules\tsyringe\dist\cjs\dependency-container.js:166:51)
    at InternalDependencyContainer.resolve (C:\snapshot\project\node_modules\tsyringe\dist\cjs\dependency-container.js:109:33)
    at Program.start (C:\snapshot\project\obj\Program.js:26:52)
    at Object.<anonymous> (C:\snapshot\project\obj\ide\ReleaseEntry.js:13:9)
    at Module._compile (pkg/prelude/bootstrap.js:1930:22)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1435:10)

错误含义

  1. 将项目编译为可执行文件时,项目根目录的package.json未被打包进最终的exe程序中
  2. modCompilerService模块需要读取package.json文件,而PreAkiModLoader的构造函数依赖注入modCompilerService
  3. 由于找不到package.json,tsyringe依赖注入容器无法正常初始化modCompilerService,进而导致PreAkiModLoader构造失败,最终程序启动崩溃

排查需补充的信息

  • 使用的pkg工具版本号
  • 项目根目录package.json的完整内容(敏感信息可打码)
  • 编译可执行文件时执行的命令,或者package.json里配置的pkg字段内容
  • modCompilerService模块中读取package.json的具体代码逻辑(是通过require还是fs模块读取?)

内容的提问来源于stack exchange,提问作者MrBox15

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 02:35:16