Bootstrap 5 ReferenceError:未定义引导程序 [英] Bootstrap 5 ReferenceError: bootstrap is not defined
问题描述
我刚刚完成安装 bootstrap 5 版本 ^5.0.0-alpha1
并在 app.js
I'm just finish install bootstrap 5 version ^5.0.0-alpha1
and import bootstrap in app.js
import "bootstrap"
other.js
var myModal = new bootstrap.Modal(document.getElementById('myModal'));
myModal.show();
当我运行代码时,它给我错误ReferenceError: bootstrap is not defined.
when I run the code it give me error ReferenceError: bootstrap is not defined.
然后我尝试像这样在 other.js 中导入引导程序
then I try to import bootstrap in other.js like this
import bootstrap from "bootstrap"
但是当我运行 npm run dev
错误 "export 'default' (imported as 'bootstrap') is not found in 'bootstrap'
but when I run npm run dev
error "export 'default' (imported as 'bootstrap') was not found in 'bootstrap'
如果我像 import { Modal } from "bootstrap"
那样手动导入模态,它会给我错误 "TypeError: Illegal invocation"
If Im import modal manually like import { Modal } from "bootstrap"
it give me error "TypeError: Illegal invocation"
推荐答案
如果有人尝试使用 webpack,这个解决方案对我有用.
If anyone trying to use with webpack, this solution worked for me.
window.bootstrap = require('bootstrap/dist/js/bootstrap.bundle.js');
这篇关于Bootstrap 5 ReferenceError:未定义引导程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!