I've integrated the mobiscroll javascript component library into my new Laravel 8 app by adding the minified css/js files to the public/css and public/js directories. However, I'd like to find a more seamless way to include these components by using npm and referencing them directly. In a React app, this would be straightforward, but how can it be achieved in Laravel?
I attempted to require the module by adding
window.mobiscroll = require('@mobiscroll/javascript');
to the bootstrap.js file, similar to how axios and _ libraries are included. Unfortunately, I'm still encountering a 'Uncaught ReferenceError: mobiscroll is not defined' when trying to initialize a component.
Adding it to the app.js file with
require('alpinejs');
require('@mobiscroll/javascript');
yielded the same error. Despite running `npm run watch` for the mix process and ensuring successful compilation, caching or compilation issues don't seem to be the problem.
I couldn't find any solutions on SO or in the Laravel documentation that specifically addressed this issue.
UPDATE: I'm facing the same problem with dayjs, which was installed via npm i dayjs. Even after adding require('dayjs') in bootstrap.js, compiling through mix, clearing caches, I continue to receive 'dayjs is not defined' errors.