I'm trying to use elasticsearch-js within my Aurelia app but running into some trouble.
After executing npm install elasticsearch
, elasticsearch is installed under: app/node_modules/elasticsearch
.
In my app.js
, I try to pull it in with import {elasticsearch} from 'elasticsearch';
and in the javascript console, I get the following error:
system.src.js:4840 GET http://localhost:9000/dist/elasticsearch.js 404 (Not Found)D @ system.src.js:4840(anonymous function) @ system.src.js:4840Promise @ shim.min.js:1847(anonymous function) @ system.src.js:4840(anonymous function) @ system.src.js:4840(anonymous function) @ system.src.js:4840(anonymous function) @ system.src.js:4840(anonymous function) @ system.src.js:4840(anonymous function) @ system.src.js:4840(anonymous function) @ system.src.js:4840(anonymous function) @ system.src.js:4840h @ shim.min.js:1773(anonymous function) @ shim.min.js:1778e @ shim.min.js:1958
aurelia-logging-console.js:62 ERROR [app-router] Error: XHR error (404 Not Found) loading http://localhost:9000/dist/elasticsearch.js(…)error @ aurelia-logging-console.js:62log @ aurelia-logging.js:36error @ aurelia-logging.js:69processResult @ aurelia-router.js:1629(anonymous function) @ aurelia-router.js:1582h @ shim.min.js:1773(anonymous function) @ shim.min.js:1778e @ shim.min.js:1958
aurelia-logging-console.js:62 ERROR [app-router] Router navigation failed, and no previous location could be restored.error @ aurelia-logging-console.js:62log @ aurelia-logging.js:36error @ aurelia-logging.js:69restorePreviousLocation @ aurelia-router.js:1671processResult @ aurelia-router.js:1632(anonymous function) @ aurelia-router.js:1582h @ shim.min.js:1773(anonymous function) @ shim.min.js:1778e @ shim.min.js:1958
I then removed it and installed with jspm install npm:elasticsearch
. This installs elasticsearch under app\jspm_packages\npm\elasticsearch@10.1.2
.
However when I try to use it in my app, I get this error in the js console:
index.js:5 Uncaught Node tls module not supported in browsers.(anonymous function) @ index.js:5(anonymous function) @ index.js:6$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ nodelibs-tls@0.1.0.js:1(anonymous function) @ nodelibs-tls@0.1.0.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ index.js:7(anonymous function) @ index.js:113$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ forever-agent@0.6.1.js:1(anonymous function) @ forever-agent@0.6.1.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ _keep_alive_agent.js:2(anonymous function) @ _keep_alive_agent.js:46$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ http.js:10(anonymous function) @ http.js:144(anonymous function) @ http.js:146$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ index.js:3(anonymous function) @ index.js:7$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ connection_pool.js:30(anonymous function) @ connection_pool.js:227(anonymous function) @ connection_pool.js:229$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ transport.js:65(anonymous function) @ transport.js:306(anonymous function) @ transport.js:308$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ client.js:3(anonymous function) @ client.js:63$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch.js:5(anonymous function) @ elasticsearch.js:11$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch@10.1.2.js:1(anonymous function) @ elasticsearch@10.1.2.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840r @ system.src.js:4840execute @ system.src.js:4840y @ system.src.js:4840x @ system.src.js:4840p @ system.src.js:4840h @ system.src.js:4840(anonymous function) @ system.src.js:4840h @ shim.min.js:1773(anonymous function) @ shim.min.js:1778e @ shim.min.js:1958
system.src.js:4840 Uncaught Uncaught Node tls module not supported in browsers.
Evaluating http://localhost:9000/jspm_packages/github/jspm/nodelibs-tls@0.1.0/index.js$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ nodelibs-tls@0.1.0.js:1(anonymous function) @ nodelibs-tls@0.1.0.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ index.js:7(anonymous function) @ index.js:113$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ forever-agent@0.6.1.js:1(anonymous function) @ forever-agent@0.6.1.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ _keep_alive_agent.js:2(anonymous function) @ _keep_alive_agent.js:46$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ http.js:10(anonymous function) @ http.js:144(anonymous function) @ http.js:146$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ index.js:3(anonymous function) @ index.js:7$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ connection_pool.js:30(anonymous function) @ connection_pool.js:227(anonymous function) @ connection_pool.js:229$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ transport.js:65(anonymous function) @ transport.js:306(anonymous function) @ transport.js:308$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ client.js:3(anonymous function) @ client.js:63$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch.js:5(anonymous function) @ elasticsearch.js:11$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch@10.1.2.js:1(anonymous function) @ elasticsearch@10.1.2.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840r @ system.src.js:4840execute @ system.src.js:4840y @ system.src.js:4840x @ system.src.js:4840p @ system.src.js:4840h @ system.src.js:4840(anonymous function) @ system.src.js:4840h @ shim.min.js:1773(anonymous function) @ shim.min.js:1778e @ shim.min.js:1958
system.src.js:4840 Uncaught Uncaught Uncaught Node tls module not supported in browsers.
Evaluating http://localhost:9000/jspm_packages/github/jspm/nodelibs-tls@0.1.0/index.js
Evaluating http://localhost:9000/jspm_packages/github/jspm/nodelibs-tls@0.1.0.js$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ index.js:7(anonymous function) @ index.js:113$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ forever-agent@0.6.1.js:1(anonymous function) @ forever-agent@0.6.1.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ _keep_alive_agent.js:2(anonymous function) @ _keep_alive_agent.js:46$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ http.js:10(anonymous function) @ http.js:144(anonymous function) @ http.js:146$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ index.js:3(anonymous function) @ index.js:7$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ connection_pool.js:30(anonymous function) @ connection_pool.js:227(anonymous function) @ connection_pool.js:229$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ transport.js:65(anonymous function) @ transport.js:306(anonymous function) @ transport.js:308$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ client.js:3(anonymous function) @ client.js:63$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch.js:5(anonymous function) @ elasticsearch.js:11$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch@10.1.2.js:1(anonymous function) @ elasticsearch@10.1.2.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840r @ system.src.js:4840execute @ system.src.js:4840y @ system.src.js:4840x @ system.src.js:4840p @ system.src.js:4840h @ system.src.js:4840(anonymous function) @ system.src.js:4840h @ shim.min.js:1773(anonymous function) @ shim.min.js:1778e @ shim.min.js:1958
system.src.js:4840 Uncaught Uncaught Uncaught Uncaught Node tls module not supported in browsers.
Evaluating http://localhost:9000/jspm_packages/github/jspm/nodelibs-tls@0.1.0/index.js
Evaluating http://localhost:9000/jspm_packages/github/jspm/nodelibs-tls@0.1.0.js
Evaluating http://localhost:9000/jspm_packages/npm/forever-agent@0.6.1/index.js$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ forever-agent@0.6.1.js:1(anonymous function) @ forever-agent@0.6.1.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ _keep_alive_agent.js:2(anonymous function) @ _keep_alive_agent.js:46$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ http.js:10(anonymous function) @ http.js:144(anonymous function) @ http.js:146$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ index.js:3(anonymous function) @ index.js:7$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ connection_pool.js:30(anonymous function) @ connection_pool.js:227(anonymous function) @ connection_pool.js:229$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ transport.js:65(anonymous function) @ transport.js:306(anonymous function) @ transport.js:308$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ client.js:3(anonymous function) @ client.js:63$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch.js:5(anonymous function) @ elasticsearch.js:11$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840s @ system.src.js:4840(anonymous function) @ system.src.js:4840a @ system.src.js:4840(anonymous function) @ elasticsearch@10.1.2.js:1(anonymous function) @ elasticsearch@10.1.2.js:2$ @ system.src.js:4840d.execute @ system.src.js:4840i @ system.src.js:4840r @ system.src.js:4840execute @ system.src.js:4840y @ system.src.js:4840x @ system.src.js:4840p @ system.src.js:4840h @ system.src.js:4840(anonymous function) @ system.src.js:4840h @ shim.min.js:1773(anonymous function) @ shim.min.js:1778e @ shim.min.js:1958
system.src.js:4840 Uncaught Uncaught Uncaught Uncaught Uncaught Node tls module not supported in browsers.
Evaluating http://localhost:9000/jspm_packages/github/jspm/nodelibs-tls@0.1.0/index.js
Evaluating http://localhost:9000/jspm_packages/github/jspm/nodelibs-tls@0.1.0.js
Evaluating http://localhost:9000/jspm_packages/npm/forever-agent@0.6.1/index.js
Evaluating http://localhost:9000/jspm_packages/npm/forever-agent@0.6.1.js
...
Does anybody know if I am doing this wrong or if the library is incompatible with Aurelia?
Here are special instructions to use elasticsearch.js in the browser . They say that:
- versions for the browser are currently experimental.
they suggest to install it with bower using:
bower install elasticsearch
Hope it helps...
Try to install it from github
jspm install elasticsearch-js=github:elastic/elasticsearch-js
Then you can use jquery module like:
import 'bootstrap'; // installed by default in aurelia-skeleton
import 'elasticsearch-js/src/elasticsearch.jquery';
let client = new $.es.Client({
hosts: 'localhost:9200';
});
or build own Client like here https://github.com/elastic/elasticsearch-js/blob/master/src/elasticsearch.jquery.js
import es from 'elasticsearch-js';
//import es from 'elasticsearch-js/src/elasticsearch';
let config = {}
// Notice that you need to provide config.defer function if you build it yourself
// http://bluebirdjs.com/docs/api/deferred-migration.html
function defer() {
var resolve, reject;
var promise = new Promise(function() {
resolve = arguments[0];
reject = arguments[1];
});
return {
resolve: resolve,
reject: reject,
promise: promise
};
}
config.defer = defer;
config.hosts = 'localhost:9200';
let client = new es.Client(config)
来源:https://stackoverflow.com/questions/34796065/importing-elasticsearch-into-aurelia