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.

setImmediate is not defined on Meteor + React

See original GitHub issue

react-instantsearch: 2.1.0 Latest versions of Chrome and FF.

Hello, I’ve just started setup react-instantsearch on my Meteor project and have strange bug.

I’m following steps from the React Instant Search Getting Started Tutorial and when I insert first widget (<Hits /> for example) I have an error in console:

modules.js?hash=35e875d…:110624 Uncaught ReferenceError: setImmediate is not defined
    at scheduleUpdate (modules.js?hash=35e875d…:110624)
    at Object.registerWidget (modules.js?hash=35e875d…:110633)
    at new Connector (modules.js?hash=35e875d…:109693)
    at modules.js?hash=35e875d…:11541
    at measureLifeCyclePerf (modules.js?hash=35e875d…:11321)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (modules.js?hash=35e875d…:11540)
    at ReactCompositeComponentWrapper._constructComponent (modules.js?hash=35e875d…:11526)
    at ReactCompositeComponentWrapper.mountComponent (modules.js?hash=35e875d…:11434)
    at Object.mountComponent (modules.js?hash=35e875d…:4461)
    at ReactDOMComponent.mountChildren (modules.js?hash=35e875d…:10623)

It refers to this code:

exports.default = createWidgetsManager;                                                                                // 6
function createWidgetsManager(onWidgetsUpdate) {                                                                       // 7
  var widgets = [];                                                                                                    // 8
  // Is an update scheduled?                                                                                           // 9
  var scheduled = false;                                                                                               // 10
                                                                                                                       // 11
  // The state manager's updates need to be batched since more than one                                                // 12
  // component can register or unregister widgets during the same tick.                                                // 13
  function scheduleUpdate() {                                                                                          // 14
    if (scheduled) {                                                                                                   // 15
      return;                                                                                                          // 16
    }                                                                                                                  // 17
    scheduled = true;                                                                                                  // 18
    setImmediate(function () {                                                                                         // 19
      scheduled = false;                                                                                               // 20
      onWidgetsUpdate();                                                                                               // 21
    });                                                                                                                // 22
  }                    

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
damonmariacommented, Feb 24, 2017

I can confirm that changing import algoliasearch from 'algoliasearch' in dom.js to import algoliasearch/src/browser/builds/algoliasearch instead gets this working in Meteor.

1reaction
mthuretcommented, May 27, 2017

Hi @Kolyasya,

Currently we are using setImmediate to perform some scheduling and it seems that this function isn’t available with meteor. We are going to change this code to be compatible with the largest lib, but in the meantime one thing you can do is using a setImmediatepolyfill like this one: https://github.com/YuzuJS/setImmediate. I tried it with a small meteor app and it seems to work fine.

Also you are going to have another issue because of the algoliaClient we use under the hood of react-instantsearch. To bypass this issue, you can retrieve the algoliaSearch client like describe here https://github.com/algolia/algoliasearch-client-javascript/issues/292 and use the algoliaClientprop on the <InstantSearch/> component to instantiate it.

Here a working example:

import algoliaClient from 'algoliasearch/src/browser/builds/algoliasearch'

<InstantSearch
        indexName="xxx"
        algoliaClient={algoliaClient('appId', 'apiKey')}
      >
</InstantSearch>

Let me know if this help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Test Error: browserType.launch: setImmediate is not ...
I just added the polyfill.js in my test class : import 'core-js'; after that setImmediate was defined again and works now as intended....
Read more >
The definitive Node.js handbook
An incredibly powerful full-stack framework, empowering you with an isomorphic approach to building apps with JavaScript and sharing code on the client and...
Read more >
Uncaught ReferenceError: Buffer is not defined angular 13 ...
Queries related to “Uncaught ReferenceError: Buffer is not defined angular 13” · Buffer is not defined · buffer is not defined react ·...
Read more >
How to use the asar.createPackage function in asar
setImmediate (() => { this.log.verbose('clearing meteor app after packing'); this. ... if (!name) return res.send({err: new Error('not defined name')}); ...
Read more >
8 Essential Node.js Interview Questions and Answers
js in the future. An exception that has bubbled all the way up to the Process level means that your application, and Node.js...
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