wasm-pack-plugin
wasm-pack-plugin copied to clipboard
Error compiling crate
Hello. Just running the example with the following traceback:
$ yarn start
yarn run v1.10.1
warning package.json: No license field
$ webpack -dw
ℹ️ Compiling your crate...
webpack is watching the files…
wasm-pack error: Compiling your crate to WebAssembly
Caused by: Process exited with exit code: 101: `cargo build` did not exit successfully.
stdout:
stderr:
Compiling wasm-bindgen v0.2.23
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-unknown-unknown` target may not be installed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: Could not compile `wasm-bindgen`.
To learn more, run the command again with --verbose.
Further, it can't resolve './pkg' in the index.js. I am assuming this is generated when the compilation is successful.
rustc 1.31.0-nightly (2c2e2c57d 2018-10-12) wasm-pack 0.5.1
Does it work when you run cargo build directly? I don't think this is related to our plugin.
We should make the error more explicit tho and abort Webpack's compilation.
@scripjs, I guess you have the target wasm32-unknown-unknown installed, right? It seems to be one of the possible causes of the error and it's likely you haven't installed it. Can you confirm it?
@xtuc @robertohuertasm Hello. I have tried to build with stable, beta, and nightly. I am on macos 10.14
Here is my rustup:
$ rustup show
Default host: x86_64-apple-darwin
installed toolchains
--------------------
stable-x86_64-apple-darwin
beta-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin
active toolchain
----------------
beta-x86_64-apple-darwin (default)
rustc 1.30.0-beta.15 (590121930 2018-10-1
cargo build fails with the following for beta. I have replaced my system username with <user> below in the tracebacks.
$ cargo build --verbose
Fresh unicode-xid v0.1.0
Fresh version_check v0.1.5
Fresh itoa v0.4.3
Fresh cfg-if v0.1.5
Fresh log v0.4.5
Fresh proc-macro2 v0.4.19
Fresh ryu v0.2.6
Fresh serde v1.0.79
Fresh quote v0.6.8
Fresh serde_json v1.0.31
Fresh lazy_static v1.1.0
Fresh syn v0.15.7
Fresh serde_derive v1.0.79
Fresh wasm-bindgen-shared v0.2.23
Fresh wasm-bindgen-backend v0.2.23
Fresh wasm-bindgen-macro-support v0.2.23
Fresh wasm-bindgen-macro v0.2.23
Fresh wasm-bindgen v0.2.23
Compiling wasm-pack-test v0.1.0 (/Users/<user>/Labs/wasm-pack-plugin/example)
Running `rustc --crate-name wasm_pack_test src/lib.rs --color always --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=07cf83bc2877d899 --out-dir /Users/<user>/Labs/wasm-pack-plugin/example/target/debug/deps -C incremental=/Users/<user>/Labs/wasm-pack-plugin/example/target/debug/incremental -L dependency=/Users/<user>/Labs/wasm-pack-plugin/example/target/debug/deps --extern wasm_bindgen=/Users/<user>/Labs/wasm-pack-plugin/example/target/debug/deps/libwasm_bindgen-3afb332ffee8d8f3.rlib`
error[E0554]: #![feature] may not be used on the beta release channel
--> src/lib.rs:1:1
|
1 | #![feature(use_extern_macros)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0554`.
error: Could not compile `wasm-pack-test`.
Caused by:
process didn't exit successfully: `rustc --crate-name wasm_pack_test src/lib.rs --color always --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=07cf83bc2877d899 --out-dir /Users/<user>/Labs/wasm-pack-plugin/example/target/debug/deps -C incremental=/Users/<user>/Labs/wasm-pack-plugin/example/target/debug/incremental -L dependency=/Users/<user>/Labs/wasm-pack-plugin/example/target/debug/deps --extern wasm_bindgen=/Users/<user>/Labs/wasm-pack-plugin/example/target/debug/deps/libwasm_bindgen-3afb332ffee8d8f3.rlib` (exit code: 1)
If I upgrade to nightly, cargo build will succeed:
$ cargo build --version
Compiling proc-macro2 v0.4.19
Compiling unicode-xid v0.1.0
Compiling ryu v0.2.6
Compiling version_check v0.1.5
Compiling serde v1.0.79
Compiling wasm-bindgen-shared v0.2.23
Compiling itoa v0.4.3
Compiling cfg-if v0.1.5
Compiling wasm-bindgen v0.2.23
Compiling log v0.4.5
Compiling lazy_static v1.1.0
Compiling quote v0.6.8
Compiling syn v0.15.7
Compiling serde_json v1.0.31
Compiling serde_derive v1.0.79
Compiling wasm-bindgen-backend v0.2.23
Compiling wasm-bindgen-macro-support v0.2.23
Compiling wasm-bindgen-macro v0.2.23
Compiling wasm-pack-test v0.1.0 (/Users/<user>/Labs/wasm-pack-plugin/example)
warning: the feature `use_extern_macros` has been stable since 1.30.0 and no longer requires an attribute to enable
--> src/lib.rs:1:12
|
1 | #![feature(use_extern_macros)]
| ^^^^^^^^^^^^^^^^^
|
= note: #[warn(stable_features)] on by default
Finished dev [unoptimized + debuginfo] target(s) in 39.52s
That said, I receive the same error as before:
$ npm start
> @ start /Users/<user>/Labs/wasm-pack-plugin/example
> webpack -dw
ℹ️ Compiling your crate...
webpack is watching the files…
wasm-pack error: Compiling your crate to WebAssembly
Caused by: Process exited with exit code: 101: `cargo build` did not exit successfully.
stdout:
stderr:
Compiling wasm-bindgen v0.2.23
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-unknown-unknown` target may not be installed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: Could not compile `wasm-bindgen`.
To learn more, run the command again with --verbose.
Hash: 64d5ebac7e1738a16c7d
Version: webpack 4.20.2
Time: 959ms
Built at: 2018-10-14 17:22:22
Asset Size Chunks Chunk Names
bundle.js 4.31 KiB main [emitted] main
index.html 182 bytes [emitted]
Entrypoint main = bundle.js
[./index.js] 53 bytes {main} [built]
ERROR in ./index.js
Module not found: Error: Can't resolve './pkg' in '/Users/<user>/Labs/wasm-pack-plugin/example'
@ ./index.js 1:0-15
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {0} [built]
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 519 bytes {0} [built]
+ 2 hidden modules
You don't have the wasm32-unknown-unknown target installed. Try this:
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default nightly
Then try again. 😉
Hello @robertohuertasm . Ok, a bit further with example but yet no ./pkg? Here is my output. Thanks for your patience.
$ yarn start
yarn run v1.10.1
warning package.json: No license field
$ webpack -dw
ℹ️ Compiling your crate...
webpack is watching the files…
wasm-pack error: Could not find `wasm-bindgen`
Hash: 64d5ebac7e1738a16c7d
Version: webpack 4.20.2
Time: 763ms
Built at: 2018-10-14 17:36:55
Asset Size Chunks Chunk Names
bundle.js 4.31 KiB main [emitted] main
index.html 182 bytes [emitted]
Entrypoint main = bundle.js
[./index.js] 53 bytes {main} [built]
ERROR in ./index.js
Module not found: Error: Can't resolve './pkg' in '/Users/<user>/Labs/wasm-pack-plugin/example'
@ ./index.js 1:0-15
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {0} [built]
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 519 bytes {0} [built]
+ 2 hidden modules
Hash: 4b88e1ad43f61002d25c
Version: webpack 4.20.2
Time: 58ms
Built at: 2018-10-14 17:36:56
Asset Size Chunks Chunk Names
index.html 182 bytes [emitted]
+ 1 hidden asset
Entrypoint main = bundle.js
1 module
ERROR in ./index.js
Module not found: Error: Can't resolve './pkg' in '/Users/<user>/Labs/wasm-pack-plugin/example'
@ ./index.js 1:0-15
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
4 modules
Hash: 64d5ebac7e1738a16c7d
Version: webpack 4.20.2
Time: 19ms
Built at: 2018-10-14 17:36:56
Asset Size Chunks Chunk Names
index.html 182 bytes [emitted]
+ 1 hidden asset
Entrypoint main = bundle.js
1 module
ERROR in ./index.js
Module not found: Error: Can't resolve './pkg' in '/Users/<user>/Labs/wasm-pack-plugin/example'
@ ./index.js 1:0-15
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
4 modules
I believe something went wrong when you installed wasm-pack because normally it should detect whether you have wasm-bindgen installed or not.
Just do cargo install wasm-bindgen-cli and let me know.
Hello, installing wasm-bindgen resulted in same issue. Ran $ cargo install wasm-pack --force with following so it all looks right.
$ cargo install wasm-pack --force
Updating crates.io index
Installing wasm-pack v0.5.1
Downloaded serde_derive v1.0.80
Downloaded serde v1.0.80
Downloaded syn v0.15.11
Compiling serde v1.0.80
Compiling proc-macro2 v0.4.20
Compiling semver-parser v0.7.0
Compiling unicode-xid v0.1.0
Compiling version_check v0.1.5
Compiling rand_core v0.3.0
Compiling build_const v0.2.1
Compiling void v1.0.2
Compiling cc v1.0.25
Compiling num-traits v0.2.6
Compiling pkg-config v0.3.14
Compiling cfg-if v0.1.5
Compiling libc v0.2.43
Compiling stable_deref_trait v1.1.1
Compiling ucd-util v0.1.1
Compiling adler32 v1.0.3
Compiling ryu v0.2.6
Compiling scopeguard v0.3.3
Compiling num-integer v0.1.39
Compiling failure_derive v0.1.2
Compiling regex v1.0.5
Compiling regex v0.2.11
Compiling lazy_static v0.2.11
Compiling slog v2.4.1
Compiling unicode-width v0.1.5
Compiling rustc-demangle v0.1.9
Compiling utf8-ranges v1.0.1
Compiling vec_map v0.8.1
Compiling ansi_term v0.11.0
Compiling byteorder v1.2.6
Compiling strsim v0.7.0
Compiling itoa v0.4.3
Compiling remove_dir_all v0.5.1
Compiling bitflags v1.0.4
Compiling podio v0.1.6
Compiling take_mut v0.2.2
Compiling termcolor v0.3.6
Compiling unreachable v1.0.0
Compiling rand_core v0.2.2
Compiling crc v1.8.1
Compiling lazy_static v1.1.0
Compiling memchr v2.1.0
Compiling owning_ref v0.3.3
Compiling miniz_oxide v0.1.3
Compiling time v0.1.40
Compiling rand v0.4.3
Compiling termios v0.3.1
Compiling atty v0.2.11
Compiling isatty v0.1.9
Compiling xattr v0.2.2
Compiling filetime v0.2.1
Compiling socket2 v0.3.8
Compiling regex-syntax v0.6.2
Compiling regex-syntax v0.5.6
Compiling clicolors-control v0.2.0
Compiling textwrap v0.10.0
Compiling term v0.5.1
Compiling backtrace v0.3.9
Compiling rand v0.5.5
Compiling smallvec v0.6.5
Compiling lock_api v0.1.4
Compiling miniz_oxide_c_api v0.1.3
Compiling bzip2-sys v0.1.6
Compiling libz-sys v1.0.24
Compiling miniz-sys v0.1.10
Compiling curl-sys v0.4.13
Compiling tar v0.4.17
Compiling msdos_time v0.1.6
Compiling tempdir v0.3.7
Compiling uuid v0.6.5
Compiling clap v2.32.0
Compiling error-chain v0.12.0
Compiling quote v0.6.8
Compiling semver v0.9.0
Compiling toml v0.4.8
Compiling serde_json v1.0.32
Compiling thread_local v0.3.6
Compiling chrono v0.4.6
Compiling aho-corasick v0.6.8
Compiling rustc_version v0.2.3
Compiling slog-async v2.3.0
Compiling syn v0.14.9
Compiling syn v0.15.11
Compiling flate2 v1.0.3
Compiling parking_lot_core v0.3.1
Compiling bzip2 v0.3.3
Compiling curl v0.4.18
Compiling slog-term v2.4.0
Compiling zip v0.4.2
Compiling os_type v2.2.0
Compiling structopt-derive v0.2.12
Compiling serde_derive v1.0.80
Compiling parking_lot v0.6.4
Compiling synstructure v0.9.0
Compiling console v0.6.2
Compiling indicatif v0.9.0
Compiling structopt v0.2.12
Compiling failure v0.1.2
Compiling which v2.0.0
Compiling cargo_metadata v0.6.0
Compiling human-panic v1.0.1
Compiling wasm-pack v0.5.1
Finished release [optimized] target(s) in 2m 37s
Replacing /Users/<user>/.cargo/bin/wasm-pack
Running yarn start giving me same result that I reported where it can't find wasm-bindgen
So if you do which wasm-bindgen, what do you get?
So installing wasm-bindgen directly:
$ cargo install wasm-bindgen
Updating crates.io index
Installing wasm-bindgen v0.2.25
error: specified package has no binaries
and $which wasm-bingen is not giving me a cargo bin path. I get nothing there.
My bad, you had to do cargo +nightly install wasm-bindgen-cli. I forgot the cli suffix! 🤦♂️
Hi. Success!! After installing wasm-bindgen-cli the version was off.
$ yarn start
yarn run v1.10.1
warning package.json: No license field
$ webpack -dw
ℹ️ Compiling your crate...
webpack is watching the files…
wasm-pack error: Running the wasm-bindgen CLI
Caused by: Process exited with exit code: 1: `wasm-bindgen` did not exit successfully.
stdout:
stderr:
error: failed to extract wasm-bindgen custom sections
caused by:
it looks like the Rust project used to create this wasm file was linked against
a different version of wasm-bindgen than this binary:
rust wasm file: 0.2.23
this binary: 0.2.25
Currently the bindgen format is unstable enough that these two version must
exactly match, so it's required that these two version are kept in sync by
either updating the wasm-bindgen dependency or this binary. You should be able
to update the wasm-bindgen dependency with:
cargo update -p wasm-bindgen
or you can update the binary with
cargo install -f wasm-bindgen-cli
if this warning fails to go away though and you're not sure what to do feel free
to open an issue at https://github.com/rustwasm/wasm-bindgen/issues!
After running cargo update -p wasm-bindgen it worked fine.
$ yarn start
yarn run v1.10.1
warning package.json: No license field
$ webpack -dw
ℹ️ Compiling your crate...
webpack is watching the files…
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
✅ Your crate has been correctly compiled
Hash: e4cf5d009ca484b52bb5
Version: webpack 4.20.2
Time: 17370ms
Built at: 2018-10-14 18:23:00
Asset Size Chunks Chunk Names
bundle.js 12.1 KiB main [emitted] main
0.bundle.js 14.1 KiB 0 [emitted]
a4d818c8ac4308c9e114.module.wasm unknown size 0 [emitted]
index.html 182 bytes [emitted]
Entrypoint main = bundle.js
[./index.js] 53 bytes {main} [built]
[./pkg/wasm_pack_test.js] 4.04 KiB {0} [built]
[./pkg/wasm_pack_test_bg.wasm] 2 MiB {0} [built]
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {0} [built]
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 519 bytes {0} [built]
+ 2 hidden modules
Hash: 7e1cdd53dc455f389539
Version: webpack 4.20.2
Time: 92ms
Built at: 2018-10-14 18:23:01
Asset Size Chunks Chunk Names
index.html 182 bytes [emitted]
+ 3 hidden assets
Entrypoint main = bundle.js
[./pkg/wasm_pack_test.js] 4.04 KiB {0} [built]
[./pkg/wasm_pack_test_bg.wasm] 2 MiB {0} [built]
+ 1 hidden module
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
4 modules
I guess you can close this issue then 😉
Before closing, what could be done to prevent this for others. I think identifying working rust version and verifying install of wasm-bindgen-cli in the README.md
I can update and send a pull request referencing this issue.
Also wanted to say thanks. I use webpack extensively and this is going to help for the future. Between rust and go wasm, its going to help bring speed to some code.
The thing is that it's wasm-pack who is supposed to be doing this check... but now I see that we're using the flag --mode no-install which prevents the reinstallation of wasm-bindgen.
I guess it would be a good idea to have this in the README as you suggested 😜! Waiting for your PR! 😉