question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InstantSearch imports EventEmitter incorrectly

See original GitHub issue

Do you want to request a feature or report a bug? Bug

Bug: What is the current behavior? We put the instantsearch.js module into our (rollup) build and got an error that internal node module “events” does not export EventEmitter.

When I looked there is an ES6 import: https://github.com/algolia/instantsearch.js/blob/541699d900ca0a20e17c5624baa1a7ab085fbf9a/src/lib/InstantSearch.js#L9 Which is a named import.

But in the relevant module at node_modules/instantsearch.js/node_modules/events/events.js, which uses CommonJS exports, the exports is defined as such: module.exports = EventEmitter; Which is a default export.

I assume in your build system this got forced into resolving, but Rollup is strict with ES imports. To have the project build I quickly changed the line in InstantSearch.js to a default import: import EventEmitter from 'events'; and it builds fine.

I also found a correct, default import being used in one of your tests: https://github.com/algolia/instantsearch.js/blob/3b659783cd659f82539d97aec2e3ca1e691797f5/src/widgets/search-box/__tests__/search-box-test.js#L2

Bug: What is the proposed solution? Make the import in InstantSearch.js a default export as shown above for correctness and consistency with the test code.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
zenmumblercommented, Mar 28, 2018

@Haroenv Had to check a bit as this was a while ago, but we switched from direct use of instantsearch.js to vue-instantsearch which removed the import {...} from "instantsearch.js" statement from our code and made Rollup not have to resolve it (Rollup is configured with esnext: true and IIFE as output, not UMD). So we didn’t actually change components, just the way it was imported in the app.

We now use the ais-index and ais-results components, with a custom combobox component that uses algoliaComponent as a mixin. Composed like so:

<ais-index :app-id="..." :api-key="..." :index-name="...">
    <stuff>...</stuff>
    <custom-combobox (template external but inlined here)>
        <more-stuff>...</more-stuff>
        <ais-results>
            <combo-item>...</combo-item>
        </ais-results>
    </custom-combobox>
</ais-index>

I also had to add an Object.assign (and ES Promise) polyfill as we have to support IE 11, but that worked fine with no other changes. Can’t point to the repo sadly, but you can check the site here: https://suburbia.io/

Thanks!

0reactions
Haroenvcommented, Mar 28, 2018

Perfect! Thanks for Giving the info 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular InstantSearch Autocomplete Problems - Open Q&A
Hi Guys, Trying to implement the following Autocomplete UX patterns. I'm however getting a range of Typescript problems with this approach, ...
Read more >
Algolia Instantsearch.js in Ionic 3 - angular - Stack Overflow
I already imported it via npm with the following command. npm install instantsearch.js --save. SearchPage.ts import { Component } from ...
Read more >
instantsearch.js - UNPKG
6, import EventEmitter from '@algolia/events'; ... [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20dispose).
Read more >
3rd Party Search App Customizations
... products appearing that shouldn't (IE. hidden products), or products appearing incorrectly (price-wise) within your store's search bar.
Read more >
react search engine - You.com
Instant search uses both server side rendering and has full routing capabilities. ... import React from "react"; import ReactDOM from "react-dom"; import ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found