简体   繁体   English

在nodejs中找不到zepto模块

[英]zepto module in nodejs not found

I am a newbie with nodejs. 我是nodejs的新手。

I installed globally modules zepto and jsdom : 我安装了全局模块zepto和jsdom:

npm install jsdom -g
npm install zepto -g

I checked with npm list -g . 我检查了npm list -g These modules are installed. 这些模块已安装。

But when I reference these two modules in a script using require: 但是,当我使用require在脚本中引用这两个模块时:

var jsdom = require("jsdom");
var Zepto = require("zepto");

I got an error message : 我收到一条错误消息:

Error: Cannot find module 'zepto'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/user554/dev/exchange/bin/getExchangeData.js:6:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

I tried with only jsdom and only zepto. 我只尝试了jsdom和zepto。 Only Zepto fails. 只有Zepto失败。

What am I missing ? 我想念什么? Thank you for your help. 谢谢您的帮助。

The zepto package is not a proper Node package. zepto软件包不是正确的Node软件包。 It installs a minified version of the Zepto lib, but it looks like it's meant for browser usage (why would it be in the NPM repository? I have no idea). 它安装了Zepto lib的缩小版本,但看起来像是供浏览器使用的(为什么它会出现在NPM存储库中?我不知道)。

Instead, try the zepto-node package. 而是尝试zepto-node软件包。

The real problem here is that you're installing globally . 真正的问题是您要全局安装。 Installing with -g is meant only for modules that provide some kind of command-line scripts (eg express-generator provides the express command that you can use from your shell prompt). 使用-g安装仅适用于提供某种命令行脚本的模块(例如, express-generator提供可在shell提示符下使用的express命令)。

Generally you install the module without -g and it will get installed locally and you can require() it just fine. 通常,您在不使用-g的情况下安装该模块,并且该模块将在本地安装,您可以使用require()很好。 However, as pointed out by @robertklep, the zepto module currently does not export anything (missing "lib" in package.json), so installing locally would not help for that particular module. 但是,如@robertklep所指出的, zepto模块当前不导出任何内容 (package.json中缺少“ lib”),因此在本地安装对该特定模块没有帮助。

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

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