Building a wasm file failed due to "unresolved import"

I was trying to build a small Wasm module, but I keep running to the unresolved import error for building wasm file. If I call my logic function from then everything works fine.

   Compiling pin-project v1.0.12                                                                                                                       
error[E0432]: unresolved import `crate::exit_sequentializer`                                                                                           
  --> C:\Users\xxx\.cargo\registry\src\\static_init-1.0.3\src\
17 | use crate::{exit_sequentializer::ExitSequentializer, lazy_sequentializer::SyncSequentializer};
   |             ^^^^^^^^^^^^^^^^^^^ could not find `exit_sequentializer` in the crate root

   Compiling wasm-bindgen-macro v0.2.83                                                                                                                
For more information about this error, try `rustc --explain E0432`.                                                                                    
error: could not compile `static_init` due to previous error                                                                                           
warning: build failed, waiting for other jobs to finish...
Error: Compiling your crate to WebAssembly failed                                                                                                      
Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Is this suppose to be a problem with the crate static_init?
I used it for saving some config.
What can be done about this issue?
Thank you

There's a #[cfg(any(elf, macho, coff))] on the static_init::exit_sequentializer module. This crate likely doesn't support WASM. That's no surprise – funky life-before-main and life-after-main usually requires OS support and link-time hacking; in a clean and very barebones environment such as WASM, it simply doesn't fly.

Putting config in a lazy static isn't a particularly good idea anyway, so just put it in a regular local variable and pass it to whichever functions may need it.

1 Like