简体   繁体   English

NodeJS 在运行 Handlebars 时出现无法找到模块 './parser' 错误

[英]NodeJS gives Cannot find module './parser' error while running Handlebars

I have written a Handlebars template and got it working successfully in the Browser.我编写了一个 Handlebars 模板并让它在浏览器中成功运行。 As a next step, I want to use the Handlebars precompiler , which is a NodeJS module.下一步,我想使用Handlebars 预编译器,它是一个 NodeJS 模块。 I downloaded Handlebars for NodeJS and all dependencies, locally (no -g).我在本地下载了 NodeJS 的 Handlebars 和所有依赖项(没有 -g)。 But I can't seem to get past this step:但我似乎无法通过这一步:

c:\node_modules> node
> require("handlebars");
Error: Cannot find module './parser'
    ...
    at Object.<anonymous> (C:\node_modules\handlebars\lib\handlebars\compiler\base.js:1:80)
    ...

I opened base.js, and line 1 looks like:我打开了 base.js,第 1 行看起来像:

var handlebars = require("./parser");

But there is no parser.js in the folder containing base.js ( see folder at github ), or any parent folder.但是包含 base.js 的文件夹中没有 parser.js ( 请参阅 github 上的文件夹)或任何父文件夹。 The NPM page for Handlebars does not mention any dependency on parser.js that I could find. HandlebarsNPM 页面没有提到我能找到的对 parser.js 的任何依赖。 I don't know if I missed an obvious step, or if I'm supposed to generate this file.我不知道我是否错过了一个明显的步骤,或者我是否应该生成这个文件。 Any help or ideas?任何帮助或想法?

为简单起见:只需在可以访问互联网的 PC 上下载所有必要的软件包(因此实际上只需在把手文件夹中运行npm install ),然后只需复制包含所有模块的文件夹

如果命令“npm install”无法解决问题,请尝试此命令,它也解决了我的问题:

yarn add http-parser-js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM