Getting Data In

require(['splunkjs/mvc'], function() { ... } gives me "require is not defined" Javascript error (SE 9.1.1)

joemcmahon
Explorer

In a modified  search_mrsparkle/templates/pages/base.html, we have a <script> tag inserted just before the </body> tag, as follows:

<script src="${make_url('/static/js/abcxyz.js')}"></script></body>

with abcxyz.js placed in the search_mrsparkle/exposed/js directory.

The abcxyz.js file has the following code:  

require(['splunkjs/mvc'], function(mvc) { ... }

which performs some magical stuff on the web page.  But when the page loads, the debugging console reports "require is not defined".  This used to work under SE 9.0.0.1 (and earlier) but now fails under SE 9.1.1.

Yes, we realize we are modifying Splunk-delivered code, but we have requirements that required us taking these drastic actions.

Anyone have any ideas on how to remedy this issue?

---------------------------------------------------------------------------
@mhoustonludlam_ @C_Mooney

Labels (1)
0 Karma

joemcmahon
Explorer

So, I found a "fix" or "workaround" that I'm not too happy about, but it seems to solve the issue.

Surrounding the "require" with a 5 second "setTimeout" call, seems to work fine, as follows:

setTimeout(function()  {
    require(['splunkjs/mvc'], function(mvc) { ... }
}, 5000);

If anyone can shed any light on this "issue", please advise.

0 Karma

_JP
Contributor

Without knowing more about your javascript, is there something happening where you are doing a require of a module that should be included with an import?  Or, you might need to load abcxyz.js in a different way because of the contents.

This answer over on StackOverflow addresses the more generic javascript quirkiness you could be running into.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...