{{ message }}
Repository navigation
fix(desktop): launch normally when NODE_ENV=development is set (#5053) - #5374
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The main process read process.env.NODE_ENV at runtime to tell a dev run from a built app, so a NODE_ENV=development exported by the user's environment switched a built app into development mode: it replaced the command line with the marktext-dev profile, skipped the single instance lock, looked for locales in the working directory, and loaded the window from ELECTRON_RENDERER_URL, which only electron-vite dev sets. The last one crashed every launch with "TypeError: Invalid URL". Check import.meta.env.DEV instead, which electron-vite fixes at build time. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 15, 2026
Contributor
This was referenced Sep 16, 2026
Jocs
added a commit
that referenced
this pull request
Sep 16, 2026
`debug` and `isDevMode` were derived from `NODE_ENV !== 'production'`, and nothing sets NODE_ENV in a packaged app, so every release ran as a debug build: the View menu offered "Show Developer Tools" and "Reload Window", the settings window bound the developer-tools shortcut, Preferences showed the keyboard debugging tools, and the command manager verified its default commands on every start. Both flags now read `import.meta.env.DEV`, which electron-vite replaces at build time — the move #5374 made for the other development checks, which left this one alone because it behaves the same whether NODE_ENV is unset or `development`. `--debug` and MARKTEXT_DEBUG still turn debug mode on. A new e2e spec launches the built app twice, plainly and with MARKTEXT_DEBUG=1, and checks that only the second one carries the three extra View menu entries. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Closes #5053
Closes #5083
Summary
Both reports show MarkText 0.19.1 on Windows crashing on every launch with:
The dialog and the issue title also show raw i18n keys (
error.unexpectedMainProcess,error.unexpectedErrorWithMessage).Cause. Both happen when the user's environment has
NODE_ENV=development, which is a common global setting on Node.js developers' machines. The main process checksprocess.env.NODE_ENVat runtime to tellelectron-vite devfrom a built app. electron-vite leavesprocess.envuntouched in the main bundle, so the user's value reaches a packaged app, and the app takes every development branch:_buildUrlWithSettingsloads the window fromprocess.env.ELECTRON_RENDERER_URL. Onlyelectron-vite devsets that variable, sonew URL(undefined)throws. This is the crash.loadTranslationslooks for locales under the working directory. It finds nothing, so every main-process string falls back to its key.cli()drops the command line (files to open,--user-data-dir) and uses themarktext-devprofile instead.Fix. These checks now read
import.meta.env.DEV, which electron-vite replaces at build time:trueunderelectron-vite dev,falseinelectron-vite build. In the built main bundle the development branches are removed.baseUrlis always thefile://URL, the lock is always requested, andELECTRON_RENDERER_URLno longer appears.Changed checks:
windows/base.ts(renderer URL),cli/index.ts(dev profile),main/index.ts(single instance lock, console log level),utils/index.ts(file log level),common/i18n.ts(locale directory), andcommon/filesystem/paths.ts(getResourcesPath, currently unused).Until a release with this fix ships, affected users can remove
NODE_ENVfrom their environment (or start MarkText from a shell where it is unset).Reproduction
On macOS with the packaged 0.19.1 app,
NODE_ENV=development marktextproduces the same stack with the same line and column numbers as both reports, plus 308Translation file not founderrors. 0.20.0-rc.2 and adevelopbuild crash the same way (_buildUrlWithSettings→Invalid URL).Type of change
Test plan
issue-5053-node-env-development.spec.ts(e2e, built app) launches withNODE_ENV=development. It checks that the window loads fromfile://, that the--user-data-dirfrom the command line is used, and that the app holds the single instance lock. It fails on develop: no window opens, and the main log showsInvalid URLat_buildUrlWithSettings. It passes with this change.launchElectrongets anenvoption so a spec can set environment variables for the app.electron-vite devstill runs in development mode. The window loadshttp://localhost:5173/?udp=…marktext-dev…, and info logs are printed.pnpm run typecheckpasses, eslint reports 0 errors on the changed files, and all desktop unit tests pass (818/818).Notes for reviewers
env.tsstill readsNODE_ENV !== 'production'forisDevModeanddebug. Those checks give the same result whetherNODE_ENVis unset ordevelopment, so they don't cause this crash, and I left them alone. Changing them would turn debug mode off in every packaged build, which is a separate decision.#5375 (#3020) changes the single instance lock call on the line after the
ifchanged here inpackages/desktop/src/main/index.ts. Whichever PR merges second needs a trivial rebase.🤖 Generated with Claude Code
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.