Gravatar for jocelyn.pedneault@ia.ca

Question by Joce, Apr 16, 2018 7:06 PM

Sitecore sites using RequireJS conflicting with Coveo Hive

Hi,

All of ours Sitecore sites use RequireJS to load JavaScript files. The problem is that script files from Coveo Hive are UMD compliant and then we get some error inside the console Chrome because it define itself inside our RequireJS and then the Coveo code is not executed because it is never required inside the page.

How can we prevent this or how are we supposed to configure Coveo Hive to prevent it to fail inside a page that contains RequireJS?

Thanks,

Joce

1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Apr 16, 2018 8:33 PM

The Coveo JavaScript Search Framework and the Coveo for Sitecore extensions both uses Webpack to build their files and load external dependencies.

I have tried to include RequireJS on a page to see how it react, and I can indeed confirm that there are some conflicts.

I have no idea if those are the same conflicts that you are getting, but let's try to at least fix this issue.

I have managed to pinpoint down part of the issue:

Webpack uses a global `require` function to include external references. When RequireJS is added, webpack instead tries to use the RequireJS methods, which does not register any external dependencies that are required.

The behavior that I get is the following error:

Uncaught TypeError: Cannot read property 'addCultureInfo' of undefined
    at en.js:28
    at en.js:33

And the Search Interface is not loaded.

However, I have managed to find a workaround: Include the Coveo Search Resources *before* including the `RequireJS` file, and everything works fine.

I really hope that it is possible for you to do this, and let me know if it worked :)

Gravatar for jocelyn.pedneault@ia.ca

Comment by Joce, Apr 17, 2018 3:54 PM

Hi François,

I had exactly this problem.

Thanks for the solution!

Joce

Gravatar for aessaoulov@tenable.com

Comment by Andrei, May 8, 2019 3:30 AM

@François Lachance-Guillemette
Is this still an issue in 2019? I am looking into integrating Coveo with a Madcap Flare-generated pages that have to use requirejs, and keep getting that same error ("Uncaught TypeError: Cannot read property $ of undefined"). It just won't recognize Coveo as an object when I load it with something like:

 requirejs.config({
     "paths": {
         "Coveo": "https://static.cloud.coveo.com/searchui/v2.4382/js/CoveoJsSearch.min"
     }
 });
require(["Coveo"], function (Coveo) {
Coveo.$( function ... );
});
Ask a question