【问题标题】:Confused about the tutorial on the "Rust ???? and WebAssembly ????" website对“Rust ???? and WebAssembly ????”的教程感到困惑网站
【发布时间】:2019-10-13 12:48:34
【问题描述】:

我在这里尝试了关于 rust 和 webassembly 的Hello World Example(在 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.

【问题讨论】:

  • 检查 ../pkg 目录并仔细检查以确保那里存在“wasm-game-of-life”。如果它没有更改 package.json 中的路径以指向它。另一个问题可能是您忘记在 wasm-game-of-life/www 子目录中运行 npm install
  • 谢谢。事实证明,我必须 npm install 两次,首先是在按照教程中的步骤更改文件之前,然后是在更改文件之后。这有点奇怪,因为它已明确声明 此命令只需要在网络上运行一次
  • 这很奇怪,但很高兴你明白了!
  • 有同样的问题(windows),在运行前运行两次安装并没有解决它。就像 OP 我尝试使用 devDependencies 和 dependencies 中的条目,但都没有奏效。 不过,我确实通过在 both 中同时输入来解决它。为了确定,我也运行了两次 install ,但从输出中我感觉只需要一次。将在下面粘贴输出(字符不足)。
  • npm install npm WARN The package wasm-game-of-life is included as both a dev and production dependency. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) added 1 package, removed 1 package and audited 9101 packages in 2.879s found 0 vulnerabilities npm install [same warnings] audited 9101 packages in 2.799s found 0 vulnerabilities

标签: rust webassembly


【解决方案1】:
  1. 将“devDependencies”更改为“依赖项”
  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"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 2019-01-15
    • 2012-11-14
    相关资源
    最近更新 更多