新鲜Handlebars安装会在第一次运行时产生ReferenceError

我正在尝试使用把手,并得到一个不知疲倦的错误。 尝试了本地安装和全局安装。

$ 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) 

其他一些有用的信息:

 $ node --version v0.6.19 $ npm --version 1.1.24 

我也试图编辑文件handlebars / base.js。 我改变了第一行的阅读

 Handlebars = this.Handlebars = {} 

这暂时消除了我收到的第一个错误。 但随后出现了一个错误:

 $ 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) 

其他人是否有安装Handlebars的问题,或有如何安装和运行的build议?

你想使用命令行句柄或尝试导入模块句柄?

第一个将要求您在安装包时使用-g参数。 后者将要求你安装没有-g参数的句柄。 -g参数仅用于在您的shell中创build命令/程序的软件包。

所以如果你用命令行编译一些文件,你可以这样做:

 npm install -g handlebars 

贝壳

 $ handlebars # should output all the command line options. 

如果你想在你的模块中使用它,你可以这样做:

 npm install handlebars 

file.js

 var Handlebars = require('handlebars'); console.log(handlebars); // should output all the methods.