修复nodejs数字信封例程错误
#node #errors #hack

在我学习生锈的旅程中,我决定拿起这本书,名为"Practical Rust Web Projects" by Shing Lyu

在上一章中,您浏览了使用wasm-pack包装WebAssembly模块的示例,并在NodeJS应用程序中使用.WASM二进制。在我需要编译应用程序的步骤中,我遇到了以下错误:

$ npm run build

> create-wasm-app@0.1.0 build
> webpack --config webpack.config.js

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

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/webpack/lib/NormalModule.js:471:10)
    at /Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/webpack/lib/NormalModule.js:503:5
    at /Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/webpack/lib/NormalModule.js:358:12
    at /Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at Array.<anonymous> (/Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:16)
    at /Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:79:9
    at /Users/paul/repos/Apress/practical-rust-web-projects/Ch06/hello-wasm/client/node_modules/graceful-fs/graceful-fs.js:78:16
    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.7.0

经过一些谷歌搜索后,我遇到了建议运行以下命令的人:

$ export NODE_OPTIONS=--openssl-legacy-provider

然后再次运行构建命令,然后编译ð

$ npm run build

> create-wasm-app@0.1.0 build
> webpack --config webpack.config.js

Hash: 1707689247fe60c788af
Version: webpack 4.42.0
Time: 67ms
Built at: 11/08/2022 7:50:56 PM
                           Asset       Size  Chunks                         Chunk Names
                  0.bootstrap.js   5.31 KiB       0  [emitted]
7e852f2346d8cc54b57a.module.wasm  296 bytes       0  [emitted] [immutable]
                    bootstrap.js     11 KiB    main  [emitted]              main
                      index.html  297 bytes          [emitted]
Entrypoint main = bootstrap.js
[../pkg/hello_wasm.js] 81 bytes {0} [built]
[../pkg/hello_wasm_bg.js] 784 bytes {0} [built]
[../pkg/hello_wasm_bg.wasm] 270 bytes {0} [built]
[./bootstrap.js] 279 bytes {main} [built]
[./index.js] 51 bytes {0} [built]
[./node_modules/webpack/buildin/harmony-module.js] (webpack)/buildin/harmony-module.js 573 bytes {0} [built]

这绝对不是生产场景中的适当解决方案,但足以让我通过示例ð

欢呼!