rust - 对 "Rust 🦀 and WebAssembly 🕸"网站上的教程感到困惑

标签 rust webassembly

我尝试了 Hello World Example关于 rust 和 webassembly 在这里(在 macbookpro 2018 上)

但是卡在了最后的测试步骤。

我按照教程修改了index.jspackage.json

index.js

import * as wasm from "wasm-game-of-life";
wasm.greet();

package.json

"devDependencies": {
  "wasm-game-of-life": "file:../pkg",
  "hello-wasm-pack": "^0.1.0",
  "webpack": "^4.29.3",
  "webpack-cli": "^3.1.0",
  "webpack-dev-server": "^3.1.5",
  "copy-webpack-plugin": "^5.0.0"
}

我还尝试在 package.json 中添加一个单独的部分,如下所示

"dependencies": {
  "wasm-game-of-life": "file:../pkg"
}

可悲的是,他们都没有工作。

我在完成示例时使用的工具链

rustup 1.18.3
rustc 1.35.0
cargo 1.35.0
npm 6.9.0
node v10.15.3

下面是确切的错误信息:

(base) ➜  www git:(master) npm run start

> create-wasm-app@0.1.0 start /Users/updrew/workspace/rust playground/wasm-game-of-life/www
> webpack-dev-server

ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /Users/updrew/workspace/rust playground/wasm-game-of-life/www
✖ 「wdm」: Hash: 2c7b176d8a66be382dd2
Version: webpack 4.32.2
Time: 332ms
Built at: 05/28/2019 11:13:57 AM
         Asset       Size  Chunks             Chunk Names
0.bootstrap.js  672 bytes       0  [emitted]
  bootstrap.js    354 KiB    main  [emitted]  main
    index.html  175 bytes          [emitted]
Entrypoint main = bootstrap.js
[0] multi (webpack)-dev-server/client?http://localhost ./bootstrap.js 40 bytes {main} [built]
[./bootstrap.js] 279 bytes {main} [built]
[./index.js] 57 bytes {0} [built]
[./node_modules/ansi-html/index.js] 4.16 KiB {main} [built]
[./node_modules/events/events.js] 13.3 KiB {main} [built]
[./node_modules/html-entities/index.js] 231 bytes {main} [built]
[./node_modules/loglevel/lib/loglevel.js] 7.68 KiB {main} [built]
[./node_modules/querystring-es3/index.js] 127 bytes {main} [built]
[./node_modules/url/url.js] 22.8 KiB {main} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost] (webpack)-dev-server/client?http://localhost 9.26 KiB {main} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.59 KiB {main} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built]
[./node_modules/webpack-dev-server/node_modules/strip-ansi/index.js] (webpack)-dev-server/node_modules/strip-ansi/index.js 161 bytes {main} [built]
[./node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 75 bytes {main} [built]
    + 12 hidden modules

ERROR in ./index.js
Module not found: Error: Can't resolve 'wasm-game-of-life' in '/Users/updrew/workspace/rust playground/wasm-game-of-life/www'
 @ ./index.js 1:0-42 2:0-10
 @ ./bootstrap.js
ℹ 「wdm」: Failed to compile.

最佳答案

  1. 将“devDependencies”更改为“dependencies”
  2. 将“hello-wasm-pack”:“^0.1.0”替换为“wasm-game-of-life”:“file:../pkg”

它看起来像这样:

"dependencies": {
  "wasm-game-of-life": "file:../pkg",
  "copy-webpack-plugin": "^5.0.0",
  "webpack": "^4.16.3",
  "webpack-cli": "^3.1.0",
  "webpack-dev-server": "^3.1.5"
}

关于rust - 对 "Rust 🦀 and WebAssembly 🕸"网站上的教程感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56334609/

相关文章:

rust - 为什么此参数在此Rust函数中正确取消引用?

javascript - 在 Rails 上加载 WebAssembly 二进制文件

google-maps - 如何在 Uno WASM 中实现 Google map

javascript - 如何使用 Go 从磁盘读取文件并将其传递给 WebAssembly?

google-chrome - WebAssembly 后 MVP 后原生客户端的 future

copy - 按值重载运算符会导致使用移动的值

rust - 为什么get方法未在reqwest中返回Response对象?

rust - 为什么我需要使用 self::core::ops?

arrays - 如何创建超过 32 个泛型类型元素的数组 T : Default?

go - Go(WebAssembly)中的malloc()和free()