How to fix PlatformIO ESP8266 WiFi.h: No Such File or Directory


When compiling your PlatformIO firmware, you see an error message like

src/main.cpp:2:10: fatal error: WiFi.h: No such file or directory

* Looking for WiFi.h dependency? Check our library registry!
* CLI  > platformio lib search "header:WiFi.h"
* Web  >

    2 | #include <WiFi.h>


Instead of

#include <WiFi.h>


#include <ESP8266WiFi.h>

Now delete the .pio folder from the project directory to ensure a clean build by using:

rm -rf .pio

In case that doesn’t help, see our article on how to fix this issue by adding the WiFi library to the dependencies: How to fix PlatformIO WiFi.h: No Such File or Directory