运行命令:

webpack entry.js -o bundle.js --mode=development

出现如下错误:

node:internal/crypto/hash:69
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:69:19)
    at Object.createHash (node:crypto:133:10)

...
...
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v18.18.0

原因:

This error is related to(be related to 与...有关) the usage of certain(某些) cryptographic(加密) functions in Node.js that are not supported in the latest versions. Specifically(具体地), it occurs(发生) because Node.js 17 and above(以上) require OpenSSL 3.0, which has stricter(更加严格的) security requirements. Webpack or one of its dependencies is trying to use a cryptographic algorithm that's no longer supported by default.

Here are a few steps you can take to resolve this issue:

1. Set Environment Variable for OpenSSL Legacy Provider(提供者)

You can set an environment variable to use the OpenSSL legacy provider. This can be done by running the following command in your terminal(终端) before running Webpack:

Windows

set NODE_OPTIONS=--openssl-legacy-provider
webpack entry.js -o bundle.js --mode=development

macOS/Linux

export NODE_OPTIONS=--openssl-legacy-provider
webpack entry.js -o bundle.js --mode=development

2. Downgrade Node.js

If the above method doesn't work, you can downgrade Node.js to version 16, which doesn't have these strict OpenSSL 3.0 requirements.

标签: none

评论已关闭