简体   繁体   English

npm http软件包仅提供package.json,没有javascript文件

[英]The npm http package only provides a package.json, no javascript files

I installed a npm package that had 'http' as a dependency, so I installed that as well. 我安装了一个以'http'为依赖的npm软件包,所以我也安装了它。 All that was downloaded by npm for 'http' was a package.json file which referenced a non-existent index.js file. npm为“ http”下载的所有文件都是一个package.json文件,该文件引用了不存在的index.js文件。 Is the index.js indeed missing from package.json or am I doing something wrong? 是package.json中确实缺少index.js还是我做错了什么?

I'm using systemJS as a library loader. 我正在使用systemJS作为库加载器。

TL;DR: you can't run server-side modules inside a browser. TL; DR:您无法在浏览器中运行服务器端模块。

From what I understand, you're trying to use server-side JavaScript modules inside of a browser, which isn't going to work. 据我了解,您正在尝试在浏览器内部使用服务器端JavaScript模块,但这将无法正常工作。 Browser have (very) limited abilities to set up network connection, or read from local file systems. 浏览器建立网络连接或从本地文件系统读取的功能非常有限。

The http dependency that you're refering to is part of the Node standard library. 您引用的http依赖项是Node标准库的一部分。 So for Node apps, running server-side, it's always available. 因此,对于在服务器端运行的Node应用程序,它始终可用。

In your case, you assumed that because require('http') didn't work (in the browser), you needed to install a separate package for that ( this package ). 在您的情况下,您假设由于require('http')在浏览器中不起作用,因此需要为此安装一个单独的软件包( 此软件包 )。

But even if that package was working properly (it isn't), it wouldn't have worked inside of a browser because it depends on other modules inside the Node standard library, that also aren't available in a browser. 但是,即使该程序包工作正常(它不是),它不会在浏览器内工作,因为它依赖于节点的标准库中的其他模块,也不可在浏览器中。

I don't know if CouchDB has a REST API itself that you would be able to use from the browser, but if not, you're going to have to implement a server-side API that will act as go-between between the browser and CouchDB. 我不知道CouchDB本身是否具有可以从浏览器使用的REST API,但是如果没有,您将必须实现一个服务器端API,该API将充当浏览器之间的中介和CouchDB。

From the browser, to talk to CouchDB, try the PouchDB library ( https://pouchdb.com/ ) and put the URL to your CouchDB in the constructor. 在浏览器中,要与CouchDB进行通信,请尝试使用PouchDB库( https://pouchdb.com/ ),并将URL放入构造函数中的CouchDB。 It's intended for connecting to a local PouchDB (javascript implementation of CouchDB) but their APIs are identical. 它旨在用于连接到本地PouchDB(CouchDB的javascript实现),但它们的API相同。 Or, try actually using a local PouchDB and then syncing between the two databases. 或者,尝试实际使用本地PouchDB,然后在两个数据库之间进行同步。

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

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