Closed
Description
When building the WASM demo app, I'm getting this error
$ npm run dev
...
i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\Projects\RustPython\wasm\demo
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
warning: unused imports: `IntoPyResult`, `PyInt`
--> vm\src\exceptions.rs:1028:47
|
1028 | builtins::{traceback::PyTracebackRef, PyInt, PyTupleRef, PyTypeRef},
| ^^^^^
1029 | function::{FuncArgs, IntoPyResult},
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `std::ops::Deref`
--> vm\src\exceptions.rs:1034:9
|
1034 | use std::ops::Deref;
| ^^^^^^^^^^^^^^^
warning: unused import: `_io::io_open as open`
--> vm\src\stdlib\io.rs:13:16
|
13 | pub(crate) use _io::io_open as open;
| ^^^^^^^^^^^^^^^^^^^^
warning: `rustpython-vm` (lib) generated 3 warnings
Finished dev [unoptimized + debuginfo] target(s) in 2.68s
[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory
[INFO]: Installing wasm-bindgen...
error: failed to parse input file as wasm
Caused by:
0: failed to parse code section
1: locals exceed maximum (at offset 18929596)
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 1
full command: "C:\\Users\\<USER>\\AppData\\Local\\.wasm-pack\\wasm-bindgen-866ccfefff3842a2\\wasm-bindgen.exe" "C:\Projects\RustPython\\target\\wasm32-unknown-unknown\\debug\\rustpython_wasm.wasm" "--out-dir" "C:\Projects\RustPython\\wasm\\lib\\pkg" "--typescript" "--target" "bundler" "--out-name" "index" "--debug"
× 「wdm」: Hash: 4cbecc264801045dd3e3
Unsure about the root cause of this error, but it looks like C:\Projects\RustPython\target\wasm32-unknown-unknown\debug\rustpython_wasm.wasm
is too big (170+MB) and hence wasm-bindgen is failing with locals exceed maximum (at offset 18929596)
. This error results in an empty pkg
directory that breaks import('rustpython') in
index.js`
Current workaround is to use the WasmPackPlugin
in release configuration in wasm/demo/webpack.conf.js
config.plugins.push(
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, '../lib'),
outDir: path.resolve(__dirname, "../lib/pkg"),
forceMode: "production"
})
);