For anyone with stable income, only debt who's interest rate is at or above the potential interest you would earn investments should be paid down first. Any debt at a rate lower than you stand to earn, should be paid over time. Any debt lower than the rate of inflation should be paid as slow as the terms allow without penalty.
So my order of priority is: high interest debt>emergency fund>tax deferred investing>ira and investing>low interest debt>even more cash holding>debt below inflation.
Not everyone has stable income. And for them, attacking debt isn't always possible, especially after they go to get their car inspected and have a $1000 bill to settle in order to get to work for their unstable income. That's starting your emergency fund goes first.
You need your initial emergency fund to reasonably cover "a bump in the road". You then get stable, attack debt, and build emergency fund to be 3-6months expenditures, in case of a serious emergency.
Only then do we begin gambling in the investment markets.
High interest debt is an emergency. Anything in the emergency category gets paid first. High interest debt is a trap, you can't hope to meet any other goal in life if you don't take care of that first.
The issue with keeping your emergency fund in an index fund is that the odds of your own personal crisis coinciding with a more widespread crisis is high.
I got furloughed in April 2020. Had my emergency fund been in index funds, I would have had to realize all those market losses in order to use my emergency fund, which would have meant my emergency fund would have been a fraction of what it actually was since it was in a savings account.