I am trying to use Handlebars, and getting an indefatigable error. Tried both local install and global install.
$ sudo npm install -g handlebars
$ handlebars
/usr/local/lib/node_modules/handlebars/lib/handlebars/base.js:8
Handlebars.VERSION = "1.0.beta.5";
^
ReferenceError: Handlebars is not defined
at /usr/local/lib/node_modules/handlebars/lib/handlebars/base.js:8:1
at Object.<anonymous> (/usr/local/lib/node_modules/handlebars/lib/handlebars/base.js:100:1)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (/usr/local/lib/node_modules/handlebars/lib/handlebars.js:1:80)
at Module._compile (module.js:446:26)
Some other useful information:
$ node --version
v0.6.19
$ npm --version
1.1.24
I also attempted to edit the file handlebars/base.js. I changed the top line to read
Handlebars = this.Handlebars = {}
which temporarily eliminated the first error I was receiving. But then a subsequent error popped up:
$ handlebars
module.js:337
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module './parser'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (/usr/local/lib/node_modules/handlebars/lib/handlebars/compiler/base.js:1:80)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
Does anyone else have problems installing Handlebars, or have advice on how to get an installation up and running?
Are you trying to use the command line handlebars or trying to import the module handlebars?
The first will require you to use the -g argument when installing package. The latter will require you to install handlebars without the -g argument. The -g argument is only used for packages that create commands/programs in your shell.
So if you are compiling some files with the command line you do:
npm install -g handlebars
Shell
$ handlebars # should output all the command line options.
If you want to use it in one of your modules you do:
npm install handlebars
file.js
var Handlebars = require('handlebars');
console.log(handlebars); // should output all the methods.