@swc/core 1.16: native addon cache validation rejects ordinary Windows directories, so require('@swc/core') throws
Summary
On Windows 11, @swc/[email protected] fails to load with Failed to load native binding because the self-loading carrier rejects the cache directory. The rejection applies to the default cache and to a custom SWC_NATIVE_BINDING_CACHE on a normal drive. 1.15.33 loads fine on the same machine.
Reproduction
mkdir t && cd t
npm init -y
npm i @swc/[email protected]
node -e "require('@swc/core')"Windows 11 Enterprise 10.0.26200, Node.js 24.19.0, x64. Installed through Bun 1.4.2 and reproduced the same way.
Error
Default cache:
SWC native addon: validate cache root C:\Users\<user>\AppData\Local\swc: cache ancestor C:\Users\<user>\AppData\Local\swc: DACL grants replacement rights 0x1f01ff to SID S-1-15-3-...AppData\Local inherits a full-control ACE for an AppContainer package SID here. That ACE is present on machines that run MSIX-packaged apps, so the default location is rejected.
Custom cache on a data drive, SWC_NATIVE_BINDING_CACHE=D:/swc-cache-test:
custom cache failed: validate cache root D:/swc-cache-test: cache ancestor D:/swc-cache-test: DACL grants replacement rights 0x1301bf to SID S-1-5-11; default cache failed: ...S-1-5-11 is Authenticated Users. A new folder on a non-system drive inherits Authenticated Users:(I)(M) by default, so nearly any folder there fails the check.
SWC_NATIVE_BINDING_CACHE=0 did not help either.
What works
A directory under the user profile whose ancestors grant rights only to the user, SYSTEM, and Administrators:
SWC_NATIVE_BINDING_CACHE=C:\Users\<user>\.swc-cacherequire('@swc/core') then returns 1.16.12. Pinning @swc/core to 1.15.33 also works, which is the workaround I am using.
Expected
Either accept the ACLs that a default Windows install produces (the user, SYSTEM, Administrators, and inherited Authenticated Users or AppContainer entries that do not target the cache leaf), or fall back to loading the addon without a cache when validation fails, or print how to fix it. Today next and any tool that loads @swc/core fails with a generic Failed to load native binding and the real reason sits several errors deep in cause.
Related design issue: #12273.
Source: swc-project/swc