Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

ReferenceError: Can't find variable for clientlib initialization

Avatar

Avatar
Validate 1
Level 1
Jeanmaradiaga
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
Jeanmaradiaga
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
Jeanmaradiaga
Level 1

10-12-2020

We have multiple components with custom javascript, the way we include this clientlibs is by adding a script tag to the component's html file.

 

<script>
window.bootstrap_component(function() {
init_component_name();
})
</script>

In our head.html we define the function bootstrap_component like so:

<script>
window.bootstrap_component = function (handler) {
if (typeof handler === 'function') {
if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") {
handler();
} else {
document.addEventListener("DOMContentLoaded", function() {
handler();
});
}
}
}
</script>

 This works just fine but for the past two years we have been getting bugs on and off from Bugsnag that say: 

ReferenceError: Can't find variable: init_component_name

 

The pages where this errors are reported work just fine, checking the browser console or the error logs from AEM has revealed nothing, no error messages, no warnings, nothing. Our current theory is that the function is being called before the page has loaded despite the safeguards in place and then again once the DOM loads. Is there anything we could do to further troubleshoot this?

 

View Entire Topic

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

10-12-2020

Hi @Jeanmaradiaga 

The init_component_name() function is not declared within the script tag, that is the reason why you are getting ReferenceError: Can't find variable: init_component_name. 

<script>
    // No init_component_name function decleration here
    window.bootstrap_component(function() {
        init_component_name();
    })
</script>

This function(init_component_name) might have attached to window object thats why it is executing fine and you don't see any console errors. Hope you got it.

AG