Skip to content

Commit e261222

Browse files
authored
Fix "crypto is not defined error" on Node.js 18 in dev (#1623)
* Add --experimental-global-webcrypto node option fix "crypto is not defined error" on Node.js 18 in dev * Only add flag when on node 18 * Missed the function
1 parent 0d38ea0 commit e261222

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.changeset/green-cheetahs-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/core": patch
3+
---
4+
5+
Add --experimental-global-webcrypto node option fix "crypto is not defined error" on Node.js 18 in dev

packages/core/src/v3/build/runtime.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ export function execOptionsForRuntime(runtime: BuildRuntime, options: ExecOption
4848

4949
const conditions = options.customConditions?.map((condition) => `--conditions=${condition}`);
5050

51-
return [importEntryPoint, conditions, process.env.NODE_OPTIONS]
51+
return [
52+
importEntryPoint,
53+
conditions,
54+
process.env.NODE_OPTIONS,
55+
nodeRuntimeNeedsGlobalWebCryptoFlag() ? "--experimental-global-webcrypto" : undefined,
56+
]
5257
.filter(Boolean)
5358
.flat()
5459
.join(" ");
@@ -58,3 +63,12 @@ export function execOptionsForRuntime(runtime: BuildRuntime, options: ExecOption
5863
}
5964
}
6065
}
66+
67+
// Detect if we are using node v18, since we don't support lower than 18, and we only need to enable the flag for v18
68+
function nodeRuntimeNeedsGlobalWebCryptoFlag(): boolean {
69+
try {
70+
return process.versions.node.startsWith("18.");
71+
} catch {
72+
return false;
73+
}
74+
}

0 commit comments

Comments
 (0)