Bring a large pot of lightly salted water to a boil. Cook spaghetti in the boiling water, stirring occasionally, until tender yet firm to the bite, about 12 minutes. Drain.
Heat olive oil in a nonstick skillet 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.