Search code examples
javascriptlaraveldebuggingreferenceerror

LARAVEL error hljs is not defined in app_debug=false


When I disable the debugbar (barryvdh/laravel-debugbar), or I put APP_DEBUG=false in .env instead of APP_DEBUG=true, I have a error with a script for image gallery (baguetteBox).

The error:

Uncaught ReferenceError: hljs is not defined at window.onload

If i not disable app_debug or debugbar, i'v not error and it's ok.. If i click on a image of my website with this error, it's bug and open image on page (in url: http://127.0.0.1/website/images/image.png), but if enable the app_debug or debugbar, image open in a "modal" of baguetteBox (normal).

Screenshot of my error: Uncaught ReferenceError: hljs is not defined at window.onload


Solution

  • When DebugBar is turned on, the library is loaded by DebugBar and hljs is defined. When DebugBar is turned off, hljs is not defined so the script breaks after hljs.initHighlighting();. Try this:

        if ( typeof oldIE === 'undefined' && Object.keys && typeof hljs !== 'undefined') {
            hljs.initHighlighting();
       }