LittleFS does not work

My sketch compiles and properly displays a web page on a browser that navigates to the server on the esp8266. The problem is clearly in retrieving the web page from flash memory since the server properly serves the Hello World string when that line is not commented out. My sketch is:

#include <Arduino.h>
#include <ESP8266WiFi.h>  // Enables the ESP8266 to connect to the local network (via WiFi)
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <FS.h>
#include <LittleFS.h>

// Create AsyncWebServer object
AsyncWebServer server(80);

void handleRoot(); // function prototypes for HTTP handlers
void handleNotFound();

const char *location = "rc";
const char *ssid = "ssid";
const char *wifi_password = "password";

void setup_wifi()
  // We start by connecting to a WiFi network
  Serial.print("Connecting to ");
  WiFi.begin(ssid, wifi_password);
  while (WiFi.status() != WL_CONNECTED)
  Serial.print("WiFi connected - ESP IP address: ");

void setup()
  // Setup wifi
  Serial.print("Location: ");

  // Initialze LittleFS
  if (!LittleFS.begin())
    Serial.println("An error has occurred while mounting LittleFS");

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
            { request->send(LittleFS, "/index.html", String(), false); });

  // server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
  //           { request->send(LittleFS, "/index.html", "text/plain"); });

  // server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
  //           { request->send(200, "text/plain", "hello world!||"); });

  server.on("/app.js", HTTP_GET, [](AsyncWebServerRequest *request)
            { request->send(LittleFS, "/app.js", String(), false); });

  Serial.println("HTTP server started");


void loop()


The platformio.ini file is:

platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 115200
board_build.filesystem = littlefs
board_build.ldscript = eagle.flash.4m3m.ld

The index.html and the app.js file are in the data directory on the same level as the src directory.

There are no compilation or linking errors.

Why is the code not retrieving and sending the index.html file?

You also uploaded the filesystem to the ESP8266 by triggering the “Upload File System Image” project task, right? Espressif 8266 — PlatformIO latest documentation

Thanks for quick response. Yes, on the tasks menu numerous times I tried both “Build Filesystem” and “Upload Filesystem”. Regards, Jim

Hi @jim, did you manage to get this to work?
Im experiencing the same issue.

ESPAsyncWebServer will serve plain json pages but if i try to serve a file from LittleFS the page keeps loading and loading.