Can't find variable: Drupal I've created a behaviours in JS but when I'm not connected as admin it show in the console this error:


  Can't find variable: Drupal


When I write console.log(Drupal) in the console explorer it show too the error.

How I can fix this error ?

Edit :

I've defined my library by this way :

myc_facebook:
  version: 1.x
  js:
    js/script.js: {}
    js/timeago.js: {}
  dependencies:
    - core/jquery
    - core/drupalSettings


I integrate my library in a block by this way :

public function build() {
        $config = $this-&gt;getConfiguration();

        // Check if the conf
        if (empty($config['token']) || empty($config['pagename']) || empty($config['pageurl']) || empty($config['limit']))
            return array('err' =&gt; array('#markup' =&gt; t('You might configure this block.')));

        $build = [];
        // Create the wrapper to include facebook posts
        $build['facebook']['timeline']['#markup'] = '&lt;div id="myc-fb-posts" class="slider"&gt;&lt;ul class="slides"&gt;&lt;/ul&gt;&lt;/div&gt;';
        // Push conf vars
        foreach ($config as $key =&gt; $value) {
            $build['#attached']['drupalSettings']['myc_fb'][$key] = $value;
        }
        // Includes libraries
        $build['#attached']['library'][] = 'myc_facebook/myc_facebook';

        return $build;
    }
Sounds like you're simply missing the dependency on core/drupal (and posibly also core/jquery) in your library, so that Drupal and JQuery get loaded, which by default it doesn't for anonymous users.