Reputation: 307
Long story short. I've installed a package via NPM into a Laravel Application. I have run npm run dev
, which has built successfully; I have also run npm run watch
while developing the application.
I have also put this line in the app.js
file:
import Push from 'push.js';
And I have included the:
<script src="{{ asset('js/app.js') }}" defer></script>
line into my main template file.
However I'm still getting this error:
Push is not defined
When trying to use the package.
(Laravel 5.8)
Upvotes: 1
Views: 334
Reputation: 180004
If you're trying to use it outside of your app.js
(and its children via import
or require
), like in a Blade template, you probably need to do window.Push = Push
in your app.js
to make it available globally. You can see this in Laravel's default install in the resources/js/bootstrap.js
. For example:
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
Upvotes: 3