fix: Windows (Git Bash) local development environment compatibility#33138
fix: Windows (Git Bash) local development environment compatibility#33138stevenkeith-consensys wants to merge 1 commit into
Conversation
Local dev on Windows/Git Bash was broken at three layers, all caused by platform-native path/line-ending differences: - babel.config.js: ignore/override path checks used forward slashes only, so on Windows Babel transformed files it must never touch (SES lockdown, expo/virtual/streams.js), injecting require() into pre-module-system code and crashing the app at startup with "[runtime not ready]: ReferenceError: Property 'require' doesn't exist". Normalized via a posixPath helper. - metro.config.js: perps-controller originModulePath checks matched forward-slash paths only; now match either separator. - Shell scripts: BASH_SOURCE arrives backslash-separated when Yarn spawns scripts on Windows, breaking script-dir resolution (yarn watch failed with "Cannot find module 'C:\Program Files\Git\update-expo-channel.js'"); adb.exe and CRLF .js.env files leave trailing \r in captured values. All fixes are no-ops on macOS/Linux: path normalization only rewrites backslashes, and CR stripping only removes \r. Verified old vs new logic produces identical output for POSIX paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
CLA Signature Action: Thank you for your submission, we really appreciate it. We ask that you read and sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just by adding a comment to this pull request with this exact sentence:
By commenting with the above message you are agreeing to the terms of the CLA. Your account will be recorded as agreeing to our CLA so you don't need to sign it again for future contributions to this repository. 0 out of 1 committers have signed the CLA. |
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
None of these changes affect:
The changes are purely build tooling improvements for Windows developer compatibility, with no functional impact on macOS/Linux CI environments where E2E tests run. No E2E test tags are warranted. Performance Test Selection: |
|
FEEDBACK
FIX REQUIRED FOR MAC BUILDthe first yarn watch:clean run on the untouched PR branch failed immediately with METAMASK_ENVIRONMENT '' is not valid, even with a valid .js.env present. The cause is the PR's CRLF fix itself:
macOS ships bash 3.2, and both scripts/build.sh and scripts/lib/dev-device-target.sh run under #!/bin/bash, so Homebrew bash doesn't save you. On bash 3.2, source of a process substitution silently reads zero bytes for a file of this size — I confirmed with a minimal repro: sourcing the 259-line .js.env.example through <(tr -d '\r' ...) loads nothing, while eval "$(tr -d '\r' < file)" loads everything correctly. So the PR's claim "every fix is a no-op on macOS/Linux" is false — it breaks yarn watch and the device-targeting env load for every macOS developer. This is a must-fix review comment. The fix is one line in each of the two files:
I applied that patch in the test worktree (both call sites) to continue; everything after that worked. |



Description
Local development on Windows with Git Bash was broken at three independent layers. All root causes are platform-native path separators (
\vs/) or line endings (CRLF vs LF) leaking into code that assumed POSIX conventions:App crashed at startup with
[runtime not ready]: ReferenceError: Property 'require' doesn't exist. Theignoreandoverridespath checks inbabel.config.jsused forward slashes only, and Metro hands Babel backslash-separated paths on Windows. Babel therefore transformed files it must never touch — the SES lockdown files and theexpo/virtual/streams.jsMetro polyfill — injectingrequire("@babel/runtime/helpers/...")into code that executes before Metro's module system definesrequire. Fixed with aposixPathseparator-normalizing helper used by every path check. This also restores the 12overridescompatibility transforms (private methods, CJS interop) that were silently not being applied on Windows.yarn watchfailed withCannot find module 'C:\Program Files\Git\update-expo-channel.js'. When Yarn spawns./scripts/build.shon Windows, bash receives a backslash-separatedBASH_SOURCE[0], so the${BASH_SOURCE[0]%/*}trim found no/, thecdfailed, and__DIRNAME__was silently empty (/update-expo-channel.jsthen gets MSYS-converted to the Git install root — hence the misleading error). Fixed by normalizing backslashes beforedirnamein the four scripts that resolve their own directory.Device targeting and env loading corrupted by CRLF:
adb.exeemits CRLF, so$(adb get-state)capturesdevice\rand equality checks fail; a CRLF.js.envexports every value with a trailing\r. Fixed by stripping\rat the read sites. Themetro.config.jsperps-controlleroriginModulePathchecks were also forward-slash-only and now match either separator.Every fix is a no-op on macOS/Linux: backslash normalization doesn't alter POSIX paths, and CR stripping doesn't alter LF files. Verified by running old vs. new logic side-by-side on POSIX-style inputs with byte-identical results, plus a unit test of the Babel config path checks against both path styles.
Changelog
CHANGELOG entry: null
Related issues
Fixes: N/A (developer-environment fix, no tracking issue)
Manual testing steps
Verified on Windows 11 + Git Bash: Metro bundles all 17,393 modules from a clean cache and the app boots on an Android 16 (API 36) emulator. Checks run locally: ESLint on changed JS files,
prettier --check,bash -non all changed scripts, and a Jest smoke run (Jest sharesbabel.config.js; the one failing test inscripts/worktree-create.test.tsfails identically onmainon Windows and is unrelated).Screenshots/Recordings
Before
Red screen on app launch (Android emulator, Windows host):
[runtime not ready]: ReferenceError: Property 'require' doesn't existAfter
App boots to the wallet normally; logcat shows
Running "MetaMask". N/A for UI screenshots — developer-tooling change with no user-facing UI.Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
🤖 Generated with Claude Code