fix(win): lazy-load pdf-parse to avoid DOMMatrix crash at startup#10
Merged
Conversation
pdf-parse 2.x bundles pdf.js, which references DOMMatrix during
module init. Electron's main-process Node context exposes DOMMatrix
on macOS but not on Windows, so eagerly requiring pdf-parse at
startup crashed Mason on every Windows launch:
ReferenceError: DOMMatrix is not defined
at Module.<anonymous> (...resources/app.asar/node_modules/.../pdf-parse...)
at Module._compile (...build/ts/main.js:22)
Move the require behind a memoized loader that runs only when a PDF
upload actually happens. Mason now starts cleanly on Windows; PDF
uploads on platforms where pdf-parse fails to load return a friendly
"PDF support isn't available on this build" error instead of taking
down the whole app.
A proper PDF fix on Windows (polyfill DOMMatrix, downgrade to v1.x,
or swap the parser) is a follow-up. For now the goal is to unblock
non-PDF Windows usage.
Co-authored-by: Isaac
Co-authored-by: Isaac
scripts/install.ps1: PowerShell installer analogous to install.sh on macOS. Auto-detects x64 vs ARM64, queries the latest GitHub release, downloads the matching "Mason Setup X.Y.Z(-arm64).exe", and runs it silently as a per-user install (no admin elevation). Launches Mason on success. MASON_VERSION env var pins to a specific tag. README: Windows section with the irm | iex one-liner, manual-install guidance with arch selection, and a note for Linux build-from-source. Also gitignores the local Makefile alongside other dev-only files. Co-authored-by: Isaac
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.
Summary
Windows users get `ReferenceError: DOMMatrix is not defined` on every Mason launch. pdf-parse 2.x bundles pdf.js which references DOMMatrix during module init; Electron's main-process Node exposes DOMMatrix on macOS but not Windows, so the eager `require("pdf-parse")` at the top of main.ts crashes the whole app.
This PR moves the require behind a memoized loader that runs only when a PDF upload actually fires. Mason now starts cleanly on Windows; PDF uploads on platforms where pdf-parse fails to load return a friendly error instead of crashing.
A proper PDF fix on Windows (polyfill DOMMatrix, downgrade to pdf-parse v1.x, or swap the parser) is a follow-up. This unblocks non-PDF Windows usage today.
Bumps to 1.3.13.
Test plan
This pull request and its description were written by Isaac.