It all started with a crash in @reown/appkit-react-native. While debugging that crash, I noticed something weird happening with valtio. The subscribe() function seemed to work fine, but proxy() wasn't behaving as expected. I decided to dig into the library code itself and added some debugging directly in node_modules/valtio/vanilla.js.
I printed proxyStateMap.get(proxyObject) in both functions, and that's when things got interesting:
proxy(): Got the correct value ✓subscribe(): Got undefined ✗Wait, what? They were completely different WeakMap instances from different valtio module instances! The proxy object was being stored in one proxyStateMap, but when subscribe() tried to find it, it was looking in a completely different proxyStateMap from a different valtio instance. That's like putting your keys in one drawer and looking for them in another.
Before I continue, here's something I had to remember: when you're adding console.log statements to library code in node_modules, your logs might not show up because modules get cached. I spent way too long wondering why my logs weren't appearing before I remembered to run:
pnpm start --reset-cache
Adding logs directly to library code is actually super helpful when you're dealing with weird behavior - you can see exactly what's happening inside the library, trace the execution flow, and peek at internal state that's not exposed through the public API. Just don't forget to clear that cache!
At this point, I was stuck. The code was working before, so what changed? I did what I should have done from the start: I checked the git history.
I went through past commits one by one until I found a commit where everything worked. Then I compared the difference between the working state and the broken state. Bingo - there it was, a single line change in .npmrc:
+ node-linker=hoisted
That one line was the culprit.
After adding node-linker=hoisted, pnpm switched to a flat structure similar to npm, and that broke the sharing mechanism by creating separate valtio instances:
node_modules/valtio (version 1.13.2) node_modules/@reown/appkit-core-react-native/node_modules/valtio (version 2.1.8) node_modules/@reown/appkit-react-native/node_modules/valtio (version 2.1.8)
Why did this happen? A few reasons:
1.13.2 (some transitive dependency), while the nested packages needed 2.1.8node-linker=hoisted, pnpm doesn't use the .pnpm virtual store structure that ensures proper symlinkingSince they were using different valtio instances, and each instance had its own proxyStateMap WeakMap, the proxy object stored in one proxyStateMap wasn't found when subscribe() looked in a different proxyStateMap.
The solution was to force all valtio dependencies to use the same version. I added this to my root package.json:
{ "pnpm": { "overrides": { "valtio": "2.1.8" } } }
Then ran pnpm install, and that was it. This:
2.1.8proxyStateMapAlternatively, I could have just removed node-linker=hoisted to go back to pnpm's default virtual store, which handles this automatically. But I needed the hoisted structure for other reasons, so the override approach worked better for me.
node_modules can reveal exactly what's happening inside the library. Just remember to use --reset-cache when debugging library code in node_modules to see your changes.node-linker=hoisted, pnpm will keep separate instances if versions differ. Use pnpm.overrides to force consistent versions across your workspace.Happy debugging!


