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就用這個。