[Ethereum] Why does truffle console work fine with testrpc but truffle serve isn’t finding accounts

truffle

I'm running testrpc on the default port 8545.

I run truffle console and test with: web3.eth.sign(web3.eth.accounts[0], web3.sha3("123"))

This works fine. According to docs the sign method only works if the account is unlocked, so it seems I should be all set.

But after successfully running init/compile/migrate, I run truffle serve and when I go to the web page on localhost:8080, I get this popup message:

"Couldn't get any accounts! Make sure your Ethereum client is configured correctly."

Best Answer

I got this error as well.

I had MetaMask Ethereum client installed but had not logged in yet.

The default truffle app.js picked up the web3 instance injected by MetaMask. Once I logged into MetaMask to create initial accounts, the error went away.