InstantSearch imports EventEmitter incorrectly
See original GitHub issueDo 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:
- Created 6 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top GitHub Comments
@Haroenv Had to check a bit as this was a while ago, but we switched from direct use of
instantsearch.js
tovue-instantsearch
which removed theimport {...} from "instantsearch.js"
statement from our code and made Rollup not have to resolve it (Rollup is configured withesnext: 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
andais-results
components, with a custom combobox component that usesalgoliaComponent
as a mixin. Composed like so: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!
Perfect! Thanks for Giving the info 😃