LaTeX baffled by BOM---Unicode's byte order mark.

The inputenc package can only work from when it is loaded, so obviously not at the very start of the document. Until then, only ASCII should be used.

For real unicode handling, use a Unicode capable engine like XeTeX or LuaTeX (in your case, xelatex or lualatex). Then you don't need inputenc (and likely want to change some other packages, too).

Update: from the April 2018 LaTeX release, UTF-8 is the default encoding of LaTeX also with non-unicode engines. Thus this error should not happen anymore (you might get different errors for non-unicode documents, though). See the LaTeX News 28 (PDF) for details.


You can e.g. change the \catcode of the three problematic bytes before you input your file:

pdflatex \catcode239=9 \catcode 187=9 \catcode 191=9 \input test-bom

You should then reset the catcodes in the document to 12.


With the upcoming LaTeX release (2018) the BOM issue will be resolved on kernel level so that there will be no need any more for the gymnastics attempted in the other answers (which of course have been necessary up to now) even for pdftex / 8bit-TeX engines.