Bring a large pot of lightly salted water to the boil. Cook spaghetti in the boiling water, stirring occasionally, until tender yet firm to the bite, about 12 minutes. Drain.
Meanwhile, heat olive oil in a large non-stick frying pan over medium-low heat and cook onions until soft and translucent, 3 to 5 minutes. Add eggplants and garlic and cook until softened, 3 to 5 minutes. Add tomatoes and capers; cook until eggplant is soft, about 20 minutes. Season with salt and pepper and stir in fresh basil.
Serve eggplant sauce over spaghetti.
You can also use fresh tomatoes in this recipe, but they should be blanched and peeled.