rust架设web执行npm init wasm-app www 报错 Error: Cannot find module '../lib/cli.js'

字号+ 编辑: 国内TP粉 修订: H波 来源: 2023-09-11 我要说两句(0)

国内有个别大厂的人闲起来没事干,对着nodejs出书神吹之后被创始人打脸。辩证看待nodejs, 牵扯到它的历史包袱还真不小。

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就用这个。

阅完此文,您的感想如何?
  • 有用

    2

  • 没用

    2

  • 开心

    0

  • 愤怒

    0

  • 可怜

    0

1.如文章侵犯了您的版权,请发邮件通知本站,该文章将在24小时内删除;
2.本站标注原创的文章,转发时烦请注明来源;
3.交流群: PHP+JS聊天群

相关课文
  • 在rust/axum框架中操作redis

  • rust编译新的wasm项目操作流程(原文: 编译 Rust 为 WebAssembly)

  • rust视图模板库askama的使用

  • axum框架当中获取请求header, 和获取header指定字段的方法

我要说说
网上宾友点评