Skip to content

Commit 94172e5

Browse files
committed
cannot reassign global.crypto on node19+, use Object.defineProperty
1 parent 069e852 commit 94172e5

13 files changed

Lines changed: 1404 additions & 667 deletions

File tree

packages/backend/package-lock.json

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"@nestjs/platform-express": "^10.2.10",
134134
"@orbitdb/core": "file:../../3rd-party/orbitdb",
135135
"@paralleldrive/cuid2": "^2.2.2",
136-
"@peculiar/webcrypto": "1.4.3",
136+
"@peculiar/webcrypto": "1.5.0",
137137
"@quiet/common": "^2.0.2-alpha.1",
138138
"@quiet/identity": "^2.0.2-alpha.2",
139139
"@quiet/logger": "^2.0.2-alpha.0",

packages/backend/src/backendManager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ export const runBackendDesktop = async (secret: string) => {
179179

180180
const isDev = process.env.NODE_ENV === 'development'
181181
const webcrypto = new Crypto()
182-
// @ts-ignore
183-
global.crypto = webcrypto
182+
183+
// https://github.com/lobehub/lobehub/issues/5315#issuecomment-2572703223
184+
Object.defineProperty(global, 'crypto', {
185+
value: webcrypto,
186+
writable: true,
187+
})
188+
184189
validateOptions(options)
185190
const resourcesPath = options.resourcesPath.trim()
186191
if (!secret) {

packages/backend/src/nest/connections-manager/connections-manager.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
107107

108108
async onModuleInit() {
109109
const webcrypto = new Crypto()
110-
// @ts-ignore
111-
global.crypto = webcrypto
110+
// https://github.com/lobehub/lobehub/issues/5315#issuecomment-2572703223
111+
Object.defineProperty(global, 'crypto', {
112+
value: webcrypto,
113+
writable: true,
114+
})
112115

113116
setEngine(
114117
'newEngine',

0 commit comments

Comments
 (0)