fix(core): Handle undefined INIT_CWD in postinstall script for ARM builds #11128
+172
−148
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 #9283 where
@swc/[email protected]
fails to install on ARM64 systems with exit code 129.Problem
The postinstall script crashes when
process.env.INIT_CWD
is undefined, which can happen on ARM systems or with certain package managers like Yarn PnP. The error occurs becausepath.resolve()
receivesundefined
as its first argument:This causes the installation to fail with exit code 129, breaking the build process on ARM platforms.
Root Cause
Two locations in
packages/core/src/postinstall.ts
used TypeScript's non-null assertion operator (!
) withprocess.env.INIT_CWD!
, assuming the environment variable would always be present:When compiled to JavaScript, these became direct property accesses that could return
undefined
, causingpath.resolve(undefined, ...)
to throw.Solution
Added proper null checks for
process.env.INIT_CWD
before using it:path.resolve()
fail crypticallyChanges
packages/core/src/postinstall.ts
to add null checkspackages/core/postinstall.js
Testing
Verified that the fix:
This restores ARM64 build functionality that worked in v1.13.5 while maintaining all existing behavior for other platforms.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.