Costco Wholesale (COST 1.01%) stock could be on the way to its first losing year since 2008, as it's down 1% year to date compared to an 11% gain for the S&P 500 index.

Over the years, the warehouse retailer has been one of the most solid bets in its sector, as the company's membership model has created competitive advantages and allowed it to grow in the U.S. and internationally.

Image source: The Motley Fool.

While rivals like Wal-Mart Stores (WMT -1.75%) struggled with the rise of e-commerce and shifting consumer patterns, Costco seemed immune as earnings per share marched steadily higher.

However, that may be changing now. Costco's comparable sales in the U.S. slipped to just 1% in its first quarter of fiscal 2017, which it reported last week, and 2% globally when adjusted for fuel prices and currency translation. That metric represents sales growth at stores open more than a year, and is the most important factor in driving sales growth and profits, as increasing sales at stores that are already open is a much more efficient way to grow profits than building new stores.

It's the slowest comparable-sales growth Costco has registered in several years:

Data source: Costco investor relations.

Time to hit the sell button?

Comparable sales are closely watched, but they aren't always the best metric to judge long-term growth potential: They could be affected by temporary conditions like weather, competitor promotions, poor merchandising decisions, or other factors outside or within the company's control.

Costco CFO Richard Galanti laid part of the blame for the poor first-quarter results on the election, as sales were particularly slow in the first two weeks of November. However, a look at the chart above shows the trend of comparable-sales growth slowing over a much longer period, as it's decelerated over the last four years in the U.S. and last year globally.

That pattern in the U.S. would seem to indicate more structural forces, like the growth of e-commerce, undermining the company's growth. Meanwhile, Costco's biggest rival, Wal-Mart, has seen comparable sales improve after declines through much of 2013 and 2014; comps are up 1.2% over the last seven quarters at its namesake stores. At Sam's Club, Wal-Mart's membership-based warehouse chain, comp sales hit 1.4% excluding fuel in its latest quarter, its best quarterly mark in at least three years.

Amazon.com (AMZN 1.30%) has seen North America e-commerce sales jump 27%, and is set to top Costco in revenue for the first time ever this year. Earlier in the year, Galanti bemoaned the prospect of people sitting at home and having whatever they wanted delivered to them, noting that Costco's model works best when customers come in to a store, participating in the so-called "treasure hunt" model.

Online sales for the first quarter were up just 8%, compared to 15% growth across the retail industry, though Galanti said that over the Thanksgiving week growth reached the low to mid-teens. While Costco has been slow to adapt to e-commerce, its rivals have been moving fast. Wal-Mart spent $3.3 billion on e-commerce start-up Jet.com this summer, and has been opening hundreds of parking-lot kiosks where customers can pick up online orders. Amazon just opened its first grocery store of what could be as many as 2,000, showing off its breakthrough "Just Walk Out" technology, and the company also made its first drone delivery -- both signs that its innovation will continue at a breakneck pace.

Though Costco's competitive advantage appears to be eroding, the stock still trades at a premium compared to its brick-and-mortar peers:

Company P/E Ratio
Costco Wholesale 29.1
Wal-Mart Stores 15.6
Target 13.8
Macy's 18.5
TJX Companies 22.7

Data source: Yahoo! Finance.

In fact, there's no brick-and-mortar retailer close to Costco's size that fetches such a steep premium.

With comparable-sales growth slowing, a management team reluctant to innovate, and an overvalued price tag, the stock looks destined to underperform in the coming years.