[英]Laravel NPM Package | Cannot Access the Package
Long story short. 长话短说。 I've installed a package via NPM into a Laravel Application.
我已经通过NPM将一个软件包安装到Laravel应用程序中。 I have run
npm run dev
, which has built successfully; 我已经运行了
npm run dev
,它已经成功构建了; I have also run npm run watch
while developing the application. 在开发应用程序时,我还运行了
npm run watch
。
I have also put this line in the app.js
file: import Push from 'push.js';
我也把这一行放在
app.js
文件中: import Push from 'push.js';
And I have included the: <script src="{{ asset('js/app.js') }}" defer></script>
我包括了:
<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
但是我仍然收到此错误:
Push is not defined
When trying to use the package. 尝试使用软件包时。
( Here is the package ) ( 这是包 )
(Laravel 5.8) (Laravel 5.8)
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. 如果您想在
app.js
之外 (以及通过import
或require
)使用它(例如在Blade模板中),则可能需要执行window.Push = Push
您的app.js
以使其在全球范围内可用。 You can see this in Laravel's default install in the resources/js/bootstrap.js
. 您可以在Laravel的默认安装中的
resources/js/bootstrap.js
看到这一点。 For example: 例如:
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.