无法设置未定义的 属性 'bootstrap'
Cannot set property 'bootstrap' of undefined
当我使用 npm 安装 bootstrap 时,我 运行 以下命令:
- npm 安装bootstrap
- npm 安装popper.js --保存
然后我得到以下目录树:
-node_module
|__bootstrap
|__jquery
|__popper
我用它:
<script type="module" src="<?php echo asset('node_modules/jquery/dist/jquery.min.js') ?>"></script>
<script type="module" src="<?php echo asset('node_modules/popper/dist/popper.min.js') ?>"></script>
<script type="module" src="<?php echo asset('node_modules/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
<link rel="stylesheet" href="<?php echo asset('node_modules/bootstrap/dist/css/bootstrap.min.css') ?>">
但是当我 运行 它时,它导出一个错误:
Uncaught TypeError: Cannot set property 'bootstrap'
of undefined
at bootstrap.min.js:6
at bootstrap.min.js:6
不知道为什么,求助!!
我的 packeage.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.16.2",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.0.1",
"jquery": "^3.3.1",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.1.10"
},
"dependencies": {
"bootstrap": "^4.1.3",
"popper.js": "^1.14.4"
}
}
删除属性 type="module"
它将起作用 - jQuery 和 Bootstrap 在缩小版本中只是普通的 ES5 文件
并从 node_modules/popper.js/dist/umd
目录安装 popper.min.js 以避免以下错误:
`Uncaught SyntaxError: Unexpected token export`
据我所知,popper.min.js
文件的位置也有误。此文件位于
node_modules/popper.js/dist
你有
node_modules/popper/dist
工作示例:
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Examplel Bootstrap page</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css" />
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">Never expand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample01" aria-controls="navbarsExample01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExample01">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<form class="form-inline my-2 my-md-0">
<input class="form-control" type="text" placeholder="Search" aria-label="Search">
</form>
</div>
</nav>
</body>
</html>
当我使用 npm 安装 bootstrap 时,我 运行 以下命令:
- npm 安装bootstrap
- npm 安装popper.js --保存
然后我得到以下目录树:
-node_module
|__bootstrap
|__jquery
|__popper
我用它:
<script type="module" src="<?php echo asset('node_modules/jquery/dist/jquery.min.js') ?>"></script>
<script type="module" src="<?php echo asset('node_modules/popper/dist/popper.min.js') ?>"></script>
<script type="module" src="<?php echo asset('node_modules/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
<link rel="stylesheet" href="<?php echo asset('node_modules/bootstrap/dist/css/bootstrap.min.css') ?>">
但是当我 运行 它时,它导出一个错误:
Uncaught TypeError: Cannot set property 'bootstrap' of undefined
at bootstrap.min.js:6 at bootstrap.min.js:6
不知道为什么,求助!! 我的 packeage.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.16.2",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.0.1",
"jquery": "^3.3.1",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.1.10"
},
"dependencies": {
"bootstrap": "^4.1.3",
"popper.js": "^1.14.4"
}
}
删除属性 type="module"
它将起作用 - jQuery 和 Bootstrap 在缩小版本中只是普通的 ES5 文件
并从 node_modules/popper.js/dist/umd
目录安装 popper.min.js 以避免以下错误:
`Uncaught SyntaxError: Unexpected token export`
据我所知,popper.min.js
文件的位置也有误。此文件位于
node_modules/popper.js/dist
你有
node_modules/popper/dist
工作示例:
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Examplel Bootstrap page</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css" />
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">Never expand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample01" aria-controls="navbarsExample01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExample01">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<form class="form-inline my-2 my-md-0">
<input class="form-control" type="text" placeholder="Search" aria-label="Search">
</form>
</div>
</nav>
</body>
</html>