最近使用 Rust 开发 Web 应用程序,尝试使用 wasm-app 模板创建一个简单的 Web 应用程序。
先使用wasm-pack创建一个新的 Rust 项目
1
wasm-pack new wasm-test
然后进入项目目录
1
cd wasm-test
接着使用wasm-pack build命令构建项目
1
wasm-pack build
然后进入wasm-test目录下的www目录,使用以下命令创建一个新的 Web 应用程序:
1
cd www
1
npm init wasm-app www
结果报错
1 2 3
$ npm init wasm-app www npm error could not determine executable to run npm error A complete log of this run can be found in: C:\Users\XU Dong\AppData\Local\npm-cache\_logs\2025-03-31T13_22_00_540Z-debug-0.log
解决方法
在官方仓库的issue发现这是个共性问题,可能是npm版本的问题。
我的npm版本是10.8.2
1 2
$ npm -v 10.8.2
于是我尝试将npm降级到10.7.0版本,使用以下命令:
1
npm install -g npm@10.7.0
然后重新运行npm init wasm-app www命令,成功创建了新的 Web 应用程序。
1 2 3 4 5 6 7 8 9 10
$ npm init wasm-app www Need to install the following packages: create-wasm-app@0.1.0 Ok to proceed? (y) y
(node:17452) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated. (Use `node --trace-deprecation ...` to show where the warning was created) i 「wds」: Project is running at http://localhost:8080/ i 「wds」: webpack output is served from / i 「wds」: Content not from webpack is served from D:\rustproject\wasm-test\www node:internal/crypto/hash:79 this[kHandle] = new _Hash(algorithm, xofLen, algorithmId, getHashCache()); ^
Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:79:19) at Object.createHash (node:crypto:139:10) at module.exports (D:\rustproject\wasm-test\www\node_modules\webpack\lib\util\createHash.js:135:53) at NormalModule._initBuildHash (D:\rustproject\wasm-test\www\node_modules\webpack\lib\NormalModule.js:417:16) at handleParseError (D:\rustproject\wasm-test\www\node_modules\webpack\lib\NormalModule.js:471:10) at D:\rustproject\wasm-test\www\node_modules\webpack\lib\NormalModule.js:503:5 at D:\rustproject\wasm-test\www\node_modules\webpack\lib\NormalModule.js:358:12 at D:\rustproject\wasm-test\www\node_modules\loader-runner\lib\LoaderRunner.js:373:3 at iterateNormalLoaders (D:\rustproject\wasm-test\www\node_modules\loader-runner\lib\LoaderRunner.js:214:10) at Array.<anonymous> (D:\rustproject\wasm-test\www\node_modules\loader-runner\lib\LoaderRunner.js:205:4) at Storage.finished (D:\rustproject\wasm-test\www\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:43:16) at D:\rustproject\wasm-test\www\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:79:9 at D:\rustproject\wasm-test\www\node_modules\graceful-fs\graceful-fs.js:78:16 at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read/context:68:3) { opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error', 'error:0308010C:digital envelope routines::unsupported' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' }
[webpack-cli] Failed to load 'D:\rustproject\wasm-test\www\webpack.config.js' config [webpack-cli] Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema. - options[0] should be an object: object { patterns, options? }