I maintain a large monorepo that uses agents, and thus also partyserver. We use pnpm, which is where the problem comes in:
partysocket exports React hooks that import from react, but doesn't declare react as any sort of dependency.
In my nextjs 16 build using webpack, this causes partysocket to be provided with a react stub that is set to null, with predictably amusing results. This is because pnpm doesn't expose any packages that aren't declared as dependencies to the package-scoped node_modules. Sorry about the minned stack trace, but this only occurs in a prod build; the problem is in the useStableSocket hook.
hook.js:608 TypeError: Cannot read properties of null (reading 'useMemo')
at t.useMemo (_app-33f08802bf0385f7.js:5525:15566)
at i.options.host (_app-33f08802bf0385f7.js:4388:3425)
at d.party (_app-33f08802bf0385f7.js:4388:3714)
at o.agent (_app-33f08802bf0385f7.js:4388:4818)
I've tried manually hacking my lockfile to force pnpm to think there is a dependency on React from partysocket, and this fixes the problem:
/partysocket@1.1.6:
resolution: {integrity: sha512-LkEk8N9hMDDsDT0iDK0zuwUDFVrVMUXFXCeN3850Ng8wtjPqPBeJlwdeY6ROlJSEh3tPoTTasXoSBYH76y118w==}
dependencies:
event-target-polyfill: 0.0.4
// added
react: '19.2.0'
// added
peerDependencies:
react: '*'
dev: false
It's worth noting:
- turbopack doesn't seem to care (unfortunately I can't use it for my prod builds for other reasons), nor does webpack have issues on
next dev
- an alternative solution using next.config to force all
react imports to resolve to the same path (bypassing pnpm's strictness) also fixes it
- ideally though the package would declare all used dependencies!
I maintain a large monorepo that uses
agents, and thus also partyserver. We usepnpm, which is where the problem comes in:partysocketexports React hooks that import fromreact, but doesn't declare react as any sort of dependency.In my nextjs 16 build using webpack, this causes partysocket to be provided with a react stub that is set to
null, with predictably amusing results. This is because pnpm doesn't expose any packages that aren't declared as dependencies to the package-scoped node_modules. Sorry about the minned stack trace, but this only occurs in a prod build; the problem is in theuseStableSockethook.I've tried manually hacking my lockfile to force pnpm to think there is a dependency on React from partysocket, and this fixes the problem:
It's worth noting:
next devreactimports to resolve to the same path (bypassing pnpm's strictness) also fixes it