Bug: Type leak (Node `process`)
Example here: https://stackblitz.com/edit/vitejs-vite-1dqccd6x?file=src%2Fmain.tsx (thanks @briskflare!)
Since moving to 0.15, importing anything from jazz-tools causes Node.js types to be pulled in to the global type scope.
❯ npm ls @types/node
[email protected] /home/projects/vitejs-vite-1dqccd6x
+-- [email protected]
| `-- [email protected]
| +-- @jest/[email protected]
| | `-- @jest/[email protected]
| | `-- @types/[email protected] deduped
| +-- @react-native/[email protected]
| | +-- @react-native/[email protected]
| | | +-- [email protected]
| | | | `-- @types/[email protected] deduped
| | | `-- [email protected]
| | | `-- @types/[email protected] deduped
| | `-- [email protected]
| | `-- [email protected]
| | `-- @types/[email protected] deduped
| +-- [email protected]
| | `-- @jest/[email protected]
| | `-- [email protected]
| | +-- @types/[email protected]
| | | `-- @types/[email protected] deduped
| | `-- @types/[email protected] deduped
| `-- [email protected]
| +-- @jest/[email protected]
| | `-- @types/[email protected] deduped
| +-- @jest/[email protected]
| | `-- @types/[email protected] deduped
| +-- @types/[email protected] deduped
| +-- [email protected]
| | `-- @types/[email protected] deduped
| `-- [email protected]
| `-- @types/[email protected] deduped
`-- [email protected]
`-- @types/[email protected]
Because of this, TypeScript includes process etc in all projects regardless of runtime environment.
@types/node is being leaked by our @op-engineering/op-sqlite dependency. This is from a fresh form example created with create-jazz-app:
❯ pnpm why @types/node
dependencies:
jazz-tools 0.15.4
└─┬ @op-engineering/op-sqlite 11.4.9
└─┬ react-native 0.80.1 peer
├─┬ @jest/create-cache-key-function 29.7.0
│ └─┬ @jest/types 29.6.3
│ └── @types/node 24.0.10
└─┬ @react-native/community-cli-plugin 0.80.1
├─┬ @react-native/dev-middleware 0.80.1
│ ├─┬ chrome-launcher 0.15.2
│ │ └── @types/node 24.0.10
│ └─┬ chromium-edge-launcher 0.2.0
│ └── @types/node 24.0.10
└─┬ metro 0.82.4
├─┬ jest-worker 29.7.0
│ ├── @types/node 24.0.10
│ └─┬ jest-util 29.7.0
│ ├─┬ @jest/types 29.6.3
│ │ └── @types/node 24.0.10
│ └── @types/node 24.0.10
├─┬ metro-config 0.82.4
│ └─┬ jest-validate 29.7.0
│ └─┬ @jest/types 29.6.3
│ └── @types/node 24.0.10
└─┬ metro-file-map 0.82.4
└─┬ jest-worker 29.7.0
├── @types/node 24.0.10
└─┬ jest-util 29.7.0
├─┬ @jest/types 29.6.3
│ └── @types/node 24.0.10
└── @types/node 24.0.10
devDependencies:
@vitejs/plugin-react 4.6.0
└─┬ vite 6.3.5 peer
└── @types/node 24.0.10 peer
vite 6.3.5
└── @types/node 24.0.10 peer
We made @op-engineering/op-sqlite a peer dependency in https://github.com/garden-co/jazz/pull/2600, so this should be addressed in our next release. I'll confirm once we release the new jazz-tools version
This should have been fixed on jazz-tools 0.15.5
Confirmed this is fixed by creating a new Jazz app with jazz-tools 0.15.5. Global Node constants (such as process) are no longer leaked
It seems the issue still exists on the playground. I'm also using 0.15.7 on my local dev and can see the issue.
You're right. I tested this fix using pnpm, and the playground example is using npm.
pnpm (and yarn) expect the host project to provide peerDependencies, but npm (after v7, and bun) will install peerDependencies. Which means @op-engineering/op-sqlite is still installed in the host project.
Reopening this issue, as we'll need to find a solution that works in npm and bun as well.
Investigating I've found that the issue can be linked to Jest: https://github.com/jestjs/jest/issues/14832
Years ago they made @types/node a dependency in all their packages to be able to use Yarn PnP -> PR
They recently decided to not move forward with PnP, so I guess that it wouldn't be a problem to revert it to a devDependency.
Going to reach the Jest team to see if they are open to fix the issue. It would take time for the update to reach us, but it's a fix that would help many people.