When I attempt to install requirejs-text
, I'm getting an error that I don't understand.
$ bower install requirejs-text
bower EMALFORMED Failed to read /Users/bgolder/projects/explorer/front/bower.json
Additional error details:
Unexpected string
In bower.json, I can't see anything wrong.
{
"name": "front",
"version": "0.0.0",
"dependencies": {
"bootstrap": "~3.1.1"
"jquery": "~1.10.2",
"requirejs": "~2.1.9",
"requirejs-text": "~2.0.10",
"underscore": "~1.5.2",
"backbone": "~1.1.0",
"modernizr": "~2.6.2"
},
"devDependencies": {},
}
If I use the verbose option on bower, I get this trace.
bower EMALFORMED Failed to read /Users/bgolder/projects/explorer/front/bower.json
Additional error details:
Unexpected string
Stack trace:
SyntaxError: Unexpected string
at Object.parse (native)
at /usr/local/lib/node_modules/bower/node_modules/bower-json/lib/json.js:41:29
at fs.js:266:14
at /usr/local/lib/node_modules/bower/node_modules/graceful-fs/graceful-fs.js:104:5
at Object.oncomplete (fs.js:107:15)
From previous event:
at readJson (/usr/local/lib/node_modules/bower/lib/util/readJson.js:17:6)
at Project._readJson (/usr/local/lib/node_modules/bower/lib/core/Project.js:539:25)
at Project._analyse (/usr/local/lib/node_modules/bower/lib/core/Project.js:445:14)
at Project.install (/usr/local/lib/node_modules/bower/lib/core/Project.js:47:17)
Console trace:
Trace
at StandardRenderer.error (/usr/local/lib/node_modules/bower/lib/renderers/StandardRenderer.js:74:17)
at Logger.<anonymous> (/usr/local/lib/node_modules/bower/bin/bower:114:22)
at Logger.EventEmitter.emit (events.js:95:17)
at Logger.emit (/usr/local/lib/node_modules/bower/node_modules/bower-logger/lib/Logger.js:29:39)
at /usr/local/lib/node_modules/bower/lib/commands/install.js:35:16
at _rejected (/usr/local/lib/node_modules/bower/node_modules/q/q.js:797:24)
at /usr/local/lib/node_modules/bower/node_modules/q/q.js:823:30
at Promise.when (/usr/local/lib/node_modules/bower/node_modules/q/q.js:1035:31)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/bower/node_modules/q/q.js:741:41)
at /usr/local/lib/node_modules/bower/node_modules/q/q.js:557:44
System info:
Bower version: 1.3.1
Node version: 0.10.26
OS: Darwin 13.1.0 x64
Which still doesn't explain what's wrong.
There are two syntax errors in your JSON file. The first error was a missing ,
after "bootstrap": "~3.1.1"
. This is why you got the error message you had. The "jquery"
string on the next line was not expected. I found this error by inspecting your file by eye. Loading it in a JavaScript or a JSON editor would also have revealed it.
The second error was the comma after {}
. A JavaScript parser won't have a problem with it but the JSON parser does. I presume a JSON editor would have revealed this problem. I discovered it by relying on the new error message I got and trial and error.
Here's the fixed file:
{
"name": "front",
"version": "0.0.0",
"dependencies": {
"bootstrap": "~3.1.1",
"jquery": "~1.10.2",
"requirejs": "~2.1.9",
"requirejs-text": "~2.0.10",
"underscore": "~1.5.2",
"backbone": "~1.1.0",
"modernizr": "~2.6.2"
},
"devDependencies": {}
}
[UPDATE]
Louis' answer is likely the correct one here! I'm letting mine in for reference, but it's probably not correct for the OP specific case.
[INITIAL ANSWER]
You are on windows, and you are using a text editor that adds a BOM to your bower.json file when editing it.
Then bower complains about it because it can't read it (EMALFORMED) - which is quite accurate, if not really helpful about what the issue is.
The solution: start your bower.json file from scratch, using a text editor that doesn't sucks (and doesn't add a BOM).
See here, and here, for other people in the same case.
(and this is unrelated to requirejs-text - it's your bower.json file which is malformed)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With