Only parse package.json when it is a file

Closes #3784