Skip to content

Problem using Elasticsearch #141

@darkadept

Description

@darkadept

I think this might be a webpack configuration issue but I'm not exactly sure.

The Problem
I cloned the repo fresh, ran npm install elasticsearch --save and placed import {Client} from 'elasticsearch' in the main_server.js file.

Running that I get an error about navigator not found. This error is an Elasticsearch error from their xhr.js file. It's looking for stuff that's not available on the server (ie. navigator and window). I traced it further and found that that file is really for the browser, not server. I believe it's getting included because the Elasticsearch npm package uses the "browser" directive in it's package.json file. This is an excerpt of that file:

"browser": {
    "./src/lib/apis/index.js": "./src/lib/apis/browser_index.js",
    "./src/lib/connectors/index.js": "./src/lib/connectors/browser_index.js",
    "./src/lib/loggers/index.js": "./src/lib/loggers/browser_index.js",
    "./test/mocks/server.js": "./test/mocks/browser_server.js",
    "lodash": "lodash-compat"
  },

The "browser" field spec is here: https://github.com/defunctzombie/package-browser-field-spec

You can actually tell webpack to ignore or include certain fields in package.json as explained here: https://webpack.github.io/docs/configuration.html#resolve-packagemains

Fix Attempt
So I tried adding that clause to my webpack server configuration telling it to ignore "browser" but that causes a bunch of other things to break.

Further Testing
To make sure that this isn't a Meteor/Elasticsearch problem I created a new Meteor (1.3) app, installed Elasticsearch and put the include in the server code. That worked fine so I guess the Meteor 1.3 npm code is importing the package properly.

Question
Does anyone have any insight as to what's going on here? When Elasticsearch gets included on the server it seems to be thinking it's on the browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions