1

After the update to Spring'15 I noticed, that behind the curtain somehow Aura is now used to include report-charts on standard page layouts. In Winter'15 the report-chart were loaded differently (I can't tell exactly how).

Now with Spring'15 on some Orgs the report-charts where not loaded anymore and I started to research the backgrounds. Consider report-charts-on-layouts only as example - the following might also happen in different contexts. I did not dig very deep into it, but the symptoms were a bunch of JS errors in the js-console, like:

ReferenceError: ES6Promise is not defined in aura_prod.js (line 38, col 363)
TypeError: $A.clientService is undefined in aura_prod.js (line 38, col 363)
TypeError: $A.initConfig is not a function in 0012000001AIC9p (line 66, col 4)
TypeError: $A.run is not a function in 0012000001AIC9p (line 2381)

I found, that the reason behind this was my the usage of require.js. I use it to load several js libraries (synchronously) in the global scope via REQUIRESCRIPT and yes I know, it's considered as hack to inject 3rd party js in the global salesforce scope. But I know there are others out there which use similar techniques, too - just as a last resort since some functionality is only possible that dirty way at this time... so I think it could be worthwhile to share my experiences anyway.

To make the story short: removing require.js perfectly removes these errors.

Now my question is, is Aura know to run well side-by-side require.js or are there any known incompatibilities between the two projects?

a) If so: did anyone find a workaround to use Aura together with require.js? Is it possibly a clash because Aura comes with own functionality comparable to parts of require.js?

b) If not: Since I did not dig deep into it, Aura might also be perfectly compatible but something on the top of it, might not. So at this time I'm only generally asking. Did anyone use require.js within REQUIRESCRIPT in a link or button and got this clash?

1

I found a partial workaround to use require.js in my use case:

The reason behind the issue is not the entire require.js library, but specifically the define API. Aura (or something related to it) seems not to allow a global define like provided by require.js.

So if one (like me) is using require.js purely to load other JS synchronously (instead of simply putting a <script> into the DOM), one could delete the define function from require.js

The define-function is located at the very end of the source (version 2.1.16). It's about line number 2000:

define = function (name, deps, callback) { ...

You can comment this function out.

In all my tests the synchronous load of JS via require( urlToScript, callback ) still perfectly works and the described clashes and errors totally disappear. Fore sure require.js is crippled after that patch - but for limited use-cases it looks quite good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.