Laravel Ui bootstrap, bootstrap 未定义

Laravel Ui bootstrap, bootstrap is not defined

我创建了一个新的 laravel 项目 laravel new project

并像这样安装 bootstrap ui:

php artisan ui bootstrap

然后编译:

npm install
npm run dev

但是当我在 app.js 中使用 bootstrap 时,就像这样:

require('./bootstrap');

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
    return new bootstrap.Tooltip(tooltipTriggerEl)
});

控制台显示以下错误:

app.js?e348:5 Uncaught ReferenceError: bootstrap is not defined
    at eval (app.js?e348:5:5)
    at Array.map (<anonymous>)
    at eval (app.js?e348:4:38)
    at Object../resources/assets/js/app.js (app.js:973:1)
    at __webpack_require__ (app.js:1060:42)
    at app.js:1214:86
    at Function.__webpack_require__.O (app.js:1097:23)
    at app.js:1217:53
    at app.js:1219:12

我必须提到我 运行 npm run dev 在对任何资源文件进行更改后,我知道 npm run watch

好的,我是这样解决问题的:

resources/js/bootstrap.js 文件中:

window._ = require('lodash');

try {
    window.$ = require('jquery');
    window.bootstrap = require('bootstrap');
} catch (e) {
    console.error(e);
}

注意这一行:window.bootstrap = require('bootstrap');