fix: copy pdf-parse, xlsx, papaparse, mammoth into packaged app bundle#518
Open
deepak0x wants to merge 1 commit intorowboatlabs:mainfrom
Open
fix: copy pdf-parse, xlsx, papaparse, mammoth into packaged app bundle#518deepak0x wants to merge 1 commit intorowboatlabs:mainfrom
deepak0x wants to merge 1 commit intorowboatlabs:mainfrom
Conversation
… app These four packages are loaded via _importDynamic (new Function pattern) in builtin-tools.ts to prevent esbuild from statically bundling pdfjs-dist's DOM polyfills into the Electron main process. As a result, esbuild cannot inline them into main.cjs, and they are not available at runtime in the packaged app. Two changes to fix this: 1. bundle.mjs: mark the four packages as esbuild external so the generated main.cjs emits require() calls for them rather than inlining them. 2. forge.config.cjs: after bundling, recursively collect all transitive and optional dependencies of the four packages from the pnpm store and copy them into .package/node_modules/. Optional deps are included because @napi-rs/canvas (required by pdfjs-dist for DOMMatrix polyfills) ships its native binaries as optional platform-specific packages. Fixes: pdf-parse, xlsx, papaparse, mammoth all fail with 'Cannot find package' in the packaged .app (issue rowboatlabs#486).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #486
The four file parser packages (
pdf-parse,xlsx,papaparse,mammoth) are loaded insidebuiltin-tools.tsusing a_importDynamicwrapper:The comment above it explains the intent — using
new Functionprevents esbuild from statically resolving the imports, which avoids pullingpdfjs-dist's DOM polyfills into the Electron main process.The problem is that this creates a conflict with how the app is packaged:
main.cjsforge.config.cjsexplicitly ignores allnode_moduleswhen packaging the appAt runtime inside the packaged
.app, when_importDynamic('pdf-parse')runs, there is nonode_modulesanywhere in the directory tree. The error is always:The same failure happens for
xlsx,papaparse, andmammoth— all four file formats inparseFileare broken.Fix
Two file changes:
bundle.mjs— mark the four packages as esbuild externals. The bundledmain.cjswill emitrequire('pdf-parse')calls instead of trying (and failing) to inline them.forge.config.cjs— after bundling, walk the pnpm store recursively and copy all transitive and optional dependencies of the four packages into.package/node_modules/. Optional dependencies are included becausepdfjs-distloads@napi-rs/canvas(an optional dep) to polyfillDOMMatrix— without itpdf-parsethrows at import time.