Cómo solucionar el error fatal de ESP-IDF: nvs_flash.h: No such file or directory

Problema

Al compilar un proyecto ESP-IDF, puedes encontrar el siguiente error:

main.cpp
/home/user/MyProject/main/main.cpp:6:10: fatal error: nvs_flash.h: No such file or directory
    6 | #include <nvs_flash.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

Solución

Necesitas asegurarte de que el componente nvs_flash esté incluido en tu proyecto. Esto se puede hacer modificando tu archivo main/CMakeLists.txt para incluir el componente nvs_flash como dependencia.

Puedes hacer esto añadiendo la línea REQUIRES nvs_flash en tu función idf_component_register. Así es como modificar tu archivo main/CMakeLists.txt:

idf_component_register_nvs_flash.cmake
idf_component_register(
  SRCS "main.cpp"
  INCLUDE_DIRS "../include"
  REQUIRES nvs_flash
)

Echa un vistazo a artículos similares por categoría: ESP-IDF ESP32