title: Adding NPM javascript library to Laravel 8
body: <p>I'm using the <a href="https://mobiscroll.com/" rel="nofollow noreferrer">mobiscroll</a> javascript component library with a new Laravel 8 app I'm building. I've used the trial scripts by simply copying the minified css / js to the <code>public/css</code> and <code>public/js</code> directories of my laravel app, and then pushing the script / css files into the layout's <code>stack</code>.</p>
  <p>I'd like to be able to require these more &quot;natively&quot; by installing the module via npm and referencing the module. In a react app I'd have no problem with this-- but how is it done in laravel?</p>
  <p>I've tried adding <code>window.mobiscroll = require('@mobiscroll/javascript');</code> to the <code>bootstrap.js</code> file, since that seems to be how the <code>axios</code> and <code>_</code> libraries are being made available, but I still am getting <code>Uncaught ReferenceError: mobiscroll is not defined</code> errors when I try to initialize a component.</p>
  <p>I also tried adding it to the <code>app.js</code> file like this:</p>
  <pre><code>require('alpinejs');
  require('@mobiscroll/javascript');
  </code></pre>
  <p>with the same error as before. I am running <code>npm run watch</code> so the <code>mix</code> process is happening and succeeding with each attempt, so I don't think it's simply a problem with caching or compilation.</p>
  <p>I didn't see anything that seemed to address this on SO or the laravel docs.</p>
  <p>EDIT: having the same issue with <code>dayjs</code>, added via <code>npm i dayjs</code>, added to <code>bootstrap.js</code> using <code>window.dayjs = require('dayjs');</code>, compiled via mix, cleared all caches, and still getting error <code>dayjs is not defined</code>.</p>