socket2: error[E0583]: file not found for module `sys`

I’m trying to build using wasm-pack build and its giving me this error:

    Compiling socket2 v0.3.9

error[E0583]: file not found for module `sys`
  --> /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.3.9/src/lib.rs:72:5
   |
72 | mod sys;
   |     ^^^
   |
   = help: name the file either sys.rs or sys/mod.rs inside the directory "/home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.3.9/src"

I’m very new at this but it seems like its pulling down the latest version of the code in this repo and failing to compile.

Any help would be greatly appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (1 by maintainers)

Most upvoted comments

As far as I can tell, this is still an issue. socket2 fails to compile on wasm becaause the sys module is only imported for a unix or windows target.

Please don’t post text as a image, you can put multiple lines line that between “```” to create a code block, see https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks.

The error shown in image seems related to wasm/axum, not Socket2. But if you’re pulling in socket2 I’m sorry to say that it won’t work for now as we don’t support wasm, see https://github.com/rust-lang/socket2/issues/268.

I ended using something like this, it works but in others cases it fails not sure why

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["full"] }
async-trait = "0.1.57"
actix-web = "4"
stdweb = "0.4.20"

Sorry, I think I just closed it because I didn’t want to see it in my list of open issues anymore and nobody seemed to care about it.

@justinmchase, haha, no problem.

I think it is still something that would be nice. There are a lot of projects that rely on socket2 that cannot be used in wasm targets due to the lack of support here. For example, I am testing how feasible it would be to use a project like warp or rocket in Rust-based CloudFlare Workers.

@Thomasdezeeuw, I was mostly commenting because this issue was closed without explanation. That would have been a helpful note to people who come across this issue. 😃