Skip to content

Commit 0ec3f3d

Browse files
committed
Fix serialize-javascript on node v18
1 parent eeb72af commit 0ec3f3d

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
22
{
3-
"pnpmShrinkwrapHash": "be66b5ed1c7f3c2a1db832792d98db6bb436ff17",
3+
"pnpmShrinkwrapHash": "8cea08431b1a848463c751666dcd35e9533ea73d",
44
"preferredVersionsHash": "029c99bd6e65c5e1f25e2848340509811ff9753c"
55
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Polyfill globalThis.crypto for Node 18, which doesn't expose it by default.
2+
// This is needed by serialize-javascript, which calls crypto.randomBytes() at module load time.
3+
// All Node 18 versions have node:crypto (the module)
4+
// All Node 18 versions have globalThis.crypto (but it's the limited Web Crypto API)
5+
// The bug is that serialize-javascript@7.0.3 assumes globalThis.crypto.randomBytes() exists,
6+
// which only works in Node 20+ where the global was enhanced
7+
if (!globalThis.crypto) {
8+
const { webcrypto } = require('node:crypto');
9+
globalThis.crypto = webcrypto;
10+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": "local-node-rig/profiles/default/config/jest.config.json"
2+
"extends": "local-node-rig/profiles/default/config/jest.config.json",
3+
"setupFiles": ["<rootDir>/config/jest-setup.js"]
34
}

0 commit comments

Comments
 (0)