如何解决编译阶段未包含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)
错误含义
- 将项目编译为可执行文件时,项目根目录的
package.json未被打包进最终的exe程序中 modCompilerService模块需要读取package.json文件,而PreAkiModLoader的构造函数依赖注入modCompilerService- 由于找不到
package.json,tsyringe依赖注入容器无法正常初始化modCompilerService,进而导致PreAkiModLoader构造失败,最终程序启动崩溃
排查需补充的信息
- 使用的pkg工具版本号
- 项目根目录
package.json的完整内容(敏感信息可打码) - 编译可执行文件时执行的命令,或者
package.json里配置的pkg字段内容 modCompilerService模块中读取package.json的具体代码逻辑(是通过require还是fs模块读取?)
内容的提问来源于stack exchange,提问作者MrBox15
相关产品推荐
相关产品推荐

