1

I was using actix-web to make my project, but after importing the serde_json crate my code refused to compile and gave this error:

error[E0432]: unresolved import `actix_web::HttpServer`
 --> src/main.rs:1:41
  |
1 | use actix_web::{web, App, HttpResponse, HttpServer};
  |                                         ^^^^^^^^^^ no `HttpServer` in the root

For more information about this error, try `rustc --explain E0432`.

which is weird, because before that it was working fine, so i decided to test it again on a different project using cargo new, with the following code presented in actix-web's documentation as an example:

use actix_web::{web, App, HttpResponse, HttpServer};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().route("/", web::get().to(HttpResponse::Ok)))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
}

and it continued to give the same error.

I tried using cargo clean to no avail, but when i degraded actix-web = "4" to actix-web = "3", in my Cargo.toml file it started working again. I'm guessing this is a more general Rust problem.

Cargo.toml :

[package]
name = "project-name"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-files = "0.6.2"
actix-web = "4"
serde_json = "1.0.94"

I'm running rustc/cargo 1.68.0 and Arch Linux-6.1.1 x86-64 if that has something to do with it.

I've asked other people to try and reproduce it but in their machine it worked.

0oz
  • 11
  • 1
  • Hello, welcome, and thanks for putting effort into what is a very well structured question :) Do I understand correctly that the code above should already produce the error, or do I need to also `use` serde_json in some way to cause it? – fresskoma Mar 12 '23 at 14:28
  • I'm assuming that, if you try building your project within the [rust docker image](https://hub.docker.com/_/rust), it will work. Maybe something strange is going on in your Cargo cache, so you [could try clearing it](https://stackoverflow.com/a/68854692/124257). – fresskoma Mar 12 '23 at 14:32
  • 1
    @fresskoma Haha, clearing the cache did work, in conjunction with cargo clean, thank you so much, after a bit of frustration it worked out. :) – 0oz Mar 12 '23 at 14:59

0 Answers0