Search code examples
rubyrubygemsbundlergithub-for-windowsgit-shell

Git Shell Ruby Bundler error parsing 'Gemfile' : Undefined local variable or method '??g'


I've installed Ruby 2.2.2 (x64) via the Windows installer.

Then from the GitHub for Windows Git Bash Shell, installed Bundler via gem install bundler.

In my site repository I've created a file called Gemfile with the line gem 'github-pages'.

However when I try to run the bundler command, I receive

[!] There was an error parsing 'Gemfile': Undefined local variable or method '??g' for Gemfile. Bundler cannot continue.

 #    from C:/Users/User/Documents/GitHub/repository/Gemfile:1
 #    -------------------------------------------
 #     >   ??g e m    ' g i t h u b p a g e s '  #   ??g e m    ' g i t h u b p a g e s '
 #    -------------------------------------------

This also occurs from the Git Shell that runs Windows PowerShell.

It appears the first character is not parsing correctly and the file is parsing twice with the error, but unsure as to why.


Solution

  • I suspect this is a byte-encoding issue. Your text editor probably saved the file in UTF-16 format (2 bytes per character) with a 2-byte BOM (Byte order mark). That's showing up as the two question marks because Bundler apparently doesn't (at least by default) handle the BOM.

    The spaces between the characters in the error messages are another clue that it's probably using UTF-16.

    I suspect Bundler requires the file to be UTF-8-encoded (8 bits per character), and without a BOM.

    To fix this, see if your code editor can be configured to save files in UTF-8.