Rust最近一直在网站上力挺wasm玩法,在执行wasm时候遇到以下问题
npm init wasm-app www internal/modules/cjs/loader.js:638 throw err; ^ Error: Cannot find module '../lib/cli.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:1) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3)
笔者是macbook pro m1, 如何解决呢?
进入/usr/local/lib目录中
cd /usr/local/lib
完全干掉node_modules再重新安装npm
sudo rm -rf node_modules brew install npm
当然前提是你安装过homebrew
但你如果觉得这个不科学, 你也可以像stackoverflow网站答案上说的那样, 先homebrew卸载npm然后再重新安装。不纠结。
另外还发现有一些奇奇怪怪的报错,例如执行上面同样的命令npm init wasm-app www返回的是:
cloning the template failed! npm ERR! code 128 npm ERR! path /Volumes/macdata/rust/whatthefuck npm ERR! command failed npm ERR! command sh -c create-wasm-app "www" npm ERR! A complete log of this run can be found in: npm ERR! /Users/castor/.npm/_logs/2021-03-04T03_30_03_998Z-debug.log
遇到这种情况, 不要迟疑, 现在就行动, 换个网络试试
Castors-Personal-Mac:whatthefuck shinchou$ npm init wasm-app www (node:7598) ExperimentalWarning: The fs.promises API is experimental 🦀 Rust + 🕸 Wasm = ❤
挺喜欢螃蟹的, 因为之前鸟哥的Yaf就用这个。