I'm trying to run example from https://truffleframework.com/tutorials/pet-shop, but when I run truffle compile I get error saying

Error parsing C:/WINDOWS/system32/TruffleTest/pet-shop-tutorial/contracts/Adoption.sol: ParsedContract.sol:1:1: ParserError: Expected pragma, import directive or contract/interface/library definition. �p r a g m a s o l i d i t y ^ 0 . 5 . 0 ;

pragma solidity ^0.5.0;

contract Adoption {
address[16] public adopters;

// Adopting a pet
function adopt(uint petId) public returns (uint) {
    require(petId >= 0 && petId <= 15);
    adopters[petId] = msg.sender;
    return petId;

function getAdopters() public view returns (address[16] memory){
    return adopters;


Remix shows no problems at all, but VS code underlines line with require asking to provide error message but it doesn't seem to be an error becasue it gives same error even if comment it out.

Screenshot of code and terminal

Thank you for any thoughts on that.

1 Answer 1


My guess is that your file is encoded in UTF-8 with BOM.

BOM encoding injects a sequence of bytes at the beginning of file mostly to signal a few things to a program reading the file. [Wikipedia]

In the case of a Solidty file, the compiler expects a file starting with pragma but with UTF-8 BOM file, it starts with random bytes like 0xEF,0xBB,0xBF followed by pragma.

Notepad++ has an option to re-encode the file UFT8 and thus remove this sequence of bytes which breaks the Solidity compilation.

enter image description here

  • Thank you for your guess Greg, you are completely right! notepad++ did the work to re-encode. And I re-opened the file before on VS code itself using UTF-8 and it came up with loads of question marks, but I didn't realise that it was random bytes as you mentioned. Thank you!
    – Karlos
    Commented Jan 17, 2019 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.