简体   繁体   English

Symfony:Webpack Encore Require()无法正常工作吗?

[英]Symfony: Webpack Encore Require() is not working?

i try to use Symfony Webpack Encore. 我尝试使用Symfony Webpack Encore。 This is my app.js included in my default controller twig. 这是我的默认控制器树枝中包含的app.js。 I cannot use BootstrapDialog. 我不能使用BootstrapDialog。

require("bootstrap");
require("bootstrap-dialog");

console.log("Hello");

$(function() {
    console.log( 'Hello with jquery' );
});

BootstrapDialog.alert('Hello from dialog');

Output: 输出:

app.js:6 Hello iam a asset
10:47:34.793 app.js:13 Uncaught ReferenceError: BootstrapDialog is not defined
at Object.<anonymous> (app.js:13)
at Object../app/Resources/public/js/app.js (app.js:28)
at __webpack_require__ (bootstrap 51bba752688cd28a7b76:54)
at webpackJsonpCallback (bootstrap 51bba752688cd28a7b76:25)
at app.js:1
(anonymous) @ app.js:13
./app/Resources/public/js/app.js @ app.js:28
__webpack_require__ @ bootstrap 51bba752688cd28a7b76:54
webpackJsonpCallback @ bootstrap 51bba752688cd28a7b76:25
(anonymous) @ app.js:1
10:47:34.810 app.js:9 Hello with jquery

npm list -g --depth=0 npm list -g --depth = 0

/usr/local/Cellar/node/9.3.0_1/lib
├── bootstrap@3.3.7
├── bootstrap3-dialog@1.35.4
├── jquery@3.2.1
└── npm@5.6.0

Have you tried 你有没有尝试过

var BootstrapDialog = require('bootstrap-dialog');

If you want to use it outside app.js , you might need to additionally add something like 如果要在app.js之外使用它,则可能需要另外添加类似

window.BootstrapDialog = BootstrapDialog;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM