@@ -3,6 +3,9 @@ import pDefer from 'p-defer'
3
3
import { monorepoPaths } from '../monorepoPaths'
4
4
import { universalSpawn } from '../utils/childProcessUtils'
5
5
import { addChildProcess } from './gulpRegistry'
6
+ import semver from 'semver'
7
+
8
+ type Env = typeof process . env
6
9
7
10
export function webpackRunner ( ) {
8
11
return runWebpack ( {
@@ -16,10 +19,27 @@ type RunWebpackCfg = {
16
19
cwd : string
17
20
prefix : string
18
21
args ?: string [ ]
19
- env ?: object
22
+ env ?: Env
20
23
devServer ?: boolean
21
24
}
22
25
26
+ // https://github.com/cypress-io/cypress/issues/18914
27
+ // Node 17+ ships with OpenSSL 3 by default, so we may need the option
28
+ // --openssl-legacy-provider so that webpack@4 can use the legacy MD4 hash
29
+ // function. This option doesn't exist on Node <17 or when it is built
30
+ // against OpenSSL 1, so we have to detect Node's major version and check
31
+ // which version of OpenSSL it was built against before spawning the process.
32
+ //
33
+ // Can be removed once the webpack version is upgraded to >= 5.61,
34
+ // which no longer relies on Node's builtin crypto.hash function.
35
+ function useLegacyOpenSSLProvider ( env : Env ) {
36
+ if ( process . versions && semver . satisfies ( process . versions . node , '>=17.0.0' ) && semver . satisfies ( process . versions . openssl , '>=3' , { includePrerelease : true } ) ) {
37
+ return { NODE_OPTIONS : `${ env . NODE_OPTIONS ?? '' } --openssl-legacy-provider` }
38
+ }
39
+
40
+ return { }
41
+ }
42
+
23
43
export async function runWebpack ( cfg : RunWebpackCfg ) {
24
44
const { cwd, args = [ ] , env = process . env , devServer = false , prefix } = cfg
25
45
const dfd = pDefer ( )
@@ -32,6 +52,7 @@ export async function runWebpack (cfg: RunWebpackCfg) {
32
52
cwd,
33
53
env : {
34
54
...( env || process . env ) ,
55
+ ...useLegacyOpenSSLProvider ( env ) ,
35
56
FORCE_COLOR : '1' ,
36
57
} ,
37
58
} ,
0 commit comments