7

I'm having trouble registering my bower.json file at Bower. Any help would be greatly appreciated.

When I try to register my project at Bower using

bower register jsnlog git://github.com/mperdeck/jsnlog.js.git -V

I get the error message:

bower jsnlog#*              EMALFORMED Failed to read C:\Users\mperdeck\AppData\Local\Temp\mperdeck-PC-mperdeck\bower\js
nlog-6944-x00dtF\bower.json

Additional error details:
Unexpected token ?

The contents of my bower.json is simply (I got rid of spaces and newlines in an attempt to solve the problem):

{"name":"jsnlog.js","main":"jsnlog.js","version":"2.4.3"}

(note that there are no ? in that file)

And here are the details that appear on the screen when I run bower register:

PS D:\dev\jsnlog\jsnlog.js> bower register jsnlog git://github.com/mperdeck/jsnlog.js.git -V
bower jsnlog#*                 resolve git://github.com/mperdeck/jsnlog.js.git#*
bower jsnlog#*                download https://github.com/mperdeck/jsnlog.js/archive/2.4.3.tar.gz
bower jsnlog#*                 extract archive.tar.gz
bower jsnlog#*              EMALFORMED Failed to read C:\Users\mperdeck\AppData\Local\Temp\mperdeck-PC-mperdeck\bower\js
nlog-6944-x00dtF\bower.json

Additional error details:
Unexpected token ?

Stack trace:
SyntaxError: Unexpected token ?
    at Object.parse (native)
    at C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\bower-json\lib\json.js:41:29
    at fs.js:266:14
    at C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\graceful-fs\graceful-fs.js:105:5
    at Object.oncomplete (fs.js:107:15)

Console trace:
Trace
    at StandardRenderer.error (C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\lib\renderers\StandardRenderer.j
s:74:17)
    at Logger.updateNotifier.packageName (C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\bin\bower:109:18)
    at Logger.EventEmitter.emit (events.js:95:17)
    at Logger.emit (C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\bower-logger\lib\Logger.js:29:
39)
    at C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\lib\commands\register.js:86:20
    at _rejected (C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:808:24)
    at C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:834:30
    at Promise.when (C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:1079:31)
    at Promise.promise.promiseDispatch (C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:752
:41)
    at C:\Users\mperdeck\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:574:44

System info:
Bower version: 1.2.8
Node version: 0.10.26
OS: Windows_NT 6.1.7601 x64
user1147862
  • 3,706
  • 5
  • 29
  • 45
  • My best guess is that you saved the bower.json with a wrong file encoding. Try re-saving it as UTF-8, and if that doesn't work, try opening and saving it in a different editor (again as utf-8). – Myrne Stol Mar 04 '14 at 10:51
  • Related: http://stackoverflow.com/questions/17944345/npm-install-cannot-read-package-json – Myrne Stol Mar 04 '14 at 10:54

3 Answers3

15

Your bower json file (as visible here: https://raw.github.com/mperdeck/jsnlog.js/2.4.3/bower.json) contains a leading invisible unicode character (likely a BOM).

This is visible in curl output: curl https://raw.github.com/mperdeck/jsnlog.js/2.4.3/bower.json

Start your bower.json file over from scratch, and use an editor that doesn't add crap :-).

Mangled Deutz
  • 11,226
  • 6
  • 35
  • 34
  • 1
    I had this issue creating the file in visual studio, I used notepad to start the file and everything worked fine. – aclave1 Sep 03 '14 at 16:45
  • 1
    The issue isn't with the editor, per se, it's with the settings the user chose when saving the file. Every text editor I can think of offers an option in the save dialog to change the encoding -- all software developers should understand what these settings are for. – Warren Rumak Dec 17 '14 at 03:29
2

The problem was caused by the encoding of my bower.json file. However, removing the BOM wasn't enough - UTF8 (without BOM) was accepted. Instead, I had to use ASCII encoding.

user1147862
  • 3,706
  • 5
  • 29
  • 45
  • 1
    As your file doesn't contain anything outside the ASCII range (as far as I can tell), a utf8 encoded or a latin1 version of it should be exactly the same (binary-wise) - so, either your editor wasn't saving in utf8 (but rather utf16), or it was still adding a BOM. Either way, bower does support utf8 properly AFAIK... – Mangled Deutz Mar 07 '14 at 11:42
2

I fixed this problem by opening the file with vim and saving with no bomb.

:setlocal nobomb 
:w 
Matt Carrier
  • 4,704
  • 5
  • 24
  • 30