I've some problem with bootstrap5 and NPM. The website design use bootstrap and works but not all the js (dropdown, modals etc...), I just would like to learn hot to import the js bs bundle without CDN. Someone can help me, please? thanks for your time
my steps:
npm install [email protected]
npm install popper.js --save
npm intsall node-sass --save-d
Package.json:
{
"name": "xlf",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "./node_modules/.bin/webpack --watch",
"sass": "node-sass --watch src/scss -o dist/css --output-style nested"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap": "^5.0.0-alpha1",
"popper.js": "^1.16.1"
},
"devDependencies": {
"node-sass": "^5.0.0",
"webpack": "^5.26.0",
"webpack-cli": "^4.5.0"
}
}
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/js/app.js',
output: {
path: path.resolve(__dirname, 'dist','js'),
filename: 'app.js',
},
mode: 'production',
module: {
rules:[
{
test: /.(scss|css)$/,
use:
[
{
options: { reloadAll: true },
},
'css-loader',
'sass-loader',
'node-sass'
]
}
]
}
};
src/js/app.js
import 'bootstrap';
src/scss/app.scss
@import '../../node_modules/bootstrap/scss/bootstrap.scss';
I've some problem with bootstrap5 and NPM. The website design use bootstrap and works but not all the js (dropdown, modals etc...), I just would like to learn hot to import the js bs bundle without CDN. Someone can help me, please? thanks for your time
my steps:
npm install [email protected]
npm install popper.js --save
npm intsall node-sass --save-d
Package.json:
{
"name": "xlf",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "./node_modules/.bin/webpack --watch",
"sass": "node-sass --watch src/scss -o dist/css --output-style nested"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap": "^5.0.0-alpha1",
"popper.js": "^1.16.1"
},
"devDependencies": {
"node-sass": "^5.0.0",
"webpack": "^5.26.0",
"webpack-cli": "^4.5.0"
}
}
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/js/app.js',
output: {
path: path.resolve(__dirname, 'dist','js'),
filename: 'app.js',
},
mode: 'production',
module: {
rules:[
{
test: /.(scss|css)$/,
use:
[
{
options: { reloadAll: true },
},
'css-loader',
'sass-loader',
'node-sass'
]
}
]
}
};
src/js/app.js
import 'bootstrap';
src/scss/app.scss
@import '../../node_modules/bootstrap/scss/bootstrap.scss';
Share
Improve this question
asked Mar 16, 2021 at 8:31
Lorenzo FranzoneLorenzo Franzone
1431 gold badge1 silver badge11 bronze badges
9
-
You are using a
alpha
version. That could be the reason. Trynpm i -S [email protected]
. – user15388024 Commented Mar 16, 2021 at 8:44 - You can narrow down the JS file in the node_modules import './node_modules/bootstrap/dist/js/bootstrap.min.js' – fatiu Commented Mar 16, 2021 at 8:51
- @jaba: tried with beta version but same result :( – Lorenzo Franzone Commented Mar 16, 2021 at 9:48
- What is the result? – user15388024 Commented Mar 16, 2021 at 9:50
- modal, dropdown ecc not working... with my code JS works only if I also add into HTML popper via CDN – Lorenzo Franzone Commented Mar 16, 2021 at 9:52
1 Answer
Reset to default 6Solved with these steps:
- installing beta versione
- uninstalling popper.js and installing @popperjs/core
- adding
import '@popperjs/core';
beforeimport 'bootstrap';
Thanks for help Jabaa.