WiFi.h or ESP8266WiFi.h not found (wrong board chosen)

  • ESP32
  • ESP8266

You may see

fatal error: WiFi.h: No such file or directory
fatal error: ESP8266WiFi.h: No such file or directory
fatal error: wl_definitions.h: No such file or directory
fatal error: esp_now.h: No such file or directory
fatal error: BluetoothSerial.h: No such file or directory

Why it happens

  • The board menu is on Arduino Uno, or on the other ESP board.
  • ESP32 code uses WiFi.h; ESP8266 code uses ESP8266WiFi.h.
  • Libraries with the same name were downloaded by hand for a different board.

How to fix it

  1. Choose your real board in Tools > Board (ESP32 Dev Module, or NodeMCU 1.0 for the ESP8266).
  2. If the board isn't listed, install it first with the Boards Manager.
  3. Don't install a library called ESP8266WiFi or WiFi from the internet: they come with the board package.
  4. Delete such a copy from Documents/Arduino/libraries if you have one.

It worked if: Verify passes with your board named at the bottom right of the IDE.

Seen in a real run (some lines are close variants of it). Produced with Arduino CLI 1.5.1 and Arduino AVR core 1.8.8 (the same compiler the Arduino IDE uses). Compiled for Arduino Uno on purpose.

Didn't help? Search another error or ask us.