在项目中使用npm init wasm-app www生成JS模板时会出现:
1.node:events:493 throw er
2.Error: spawn git ENOENT at ChildProcess._handle.onexit (node:internal/child_process:286:19) at onErrorNT (node:internal/child_process:484:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) Emitted 'error' event on ChildProcess instance at: at ChildProcess._handle.onexit (node:internal/child_process:292:12) at onErrorNT (node:internal/child_process:484:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { errno: -4058, code: 'ENOENT', syscall: 'spawn git', path: 'git', spawnargs: [ 'clone', 'https://github.com/rustwasm/create-wasm-app.git', 'www' ] }
3.Node.js v21.1.0 npm ERR! code 1...
出现诸如此类的问题,首先确保node已经更新至最新版本。在使用这条命令时,git会从github的目标地址clone相关的JS模板(作为一个子文件夹放在当前目录下),所以,需要添加Git的环境变量使其在命令行中生效。
一般git下载后默认会存放在C盘下的Program files文件夹中,将Git文件夹下的“/bin”和“/usr/bin”目录放在系统环境变量的Path中,重启命令行。即可生效。
结果图如下:
(www文件夹及其子文件如图)