Help: How to add the latest Bootstrap 4 beta into projects
I am trying to add Bootstrap in project by using pure bootstrap lib and its dependencies, and got the following webpack errors in browser console when start up applications.
Uncaught SyntaxError: Unexpected token export
at eval (<anonymous>)
at webpackJsonp.177.module.exports (addScript.js:9)
at Object.258 (popper.js?8c93:1)
at __webpack_require__ (bootstrap 468a117c48e582c06697:52)
at Object.608 (scripts.bundle.js:66)
at __webpack_require__ (bootstrap 468a117c48e582c06697:52)
at webpackJsonpCallback (bootstrap 468a117c48e582c06697:23)
at scripts.bundle.js:1
webpackJsonp.177.module.exports @ addScript.js:9
258 @ popper.js?8c93:1
__webpack_require__ @ bootstrap 468a117c48e582c06697:52
608 @ scripts.bundle.js:66
__webpack_require__ @ bootstrap 468a117c48e582c06697:52
webpackJsonpCallback @ bootstrap 468a117c48e582c06697:23
(anonymous) @ scripts.bundle.js:1
I have encountered similar problems in before projects when importing JQuery in a webpack build, and webpack ProviderPlugin can fix it. I am not sure this is a JQuery problem, it seems load PopperJS by webpack caused some problems.
And I followed the Wiki stories global libs, but replace it with the latest Bootsrap 4 beta in .angular-cli.js.
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css",
"forms.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/popper.js/dist/popper.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
I have installed the dependencies in projects.
//package.json
"dependencies": {
"bootstrap": "^4.0.0-beta",
"jquery": "^3.2.1",
"popper.js": "^1.12.5",
....
},
Don't think this is relevant to CLI. If you take a look at bootstrap docs You will find that they ask you to include jquery's slim version. And the error about export token can be eliminated by importing umd version of popper.js`
Here is what they're importing
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
So if you update your angular cli json to look like
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.css",
"styles.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.slim.js",
"../node_modules/popper.js/dist/umd/popper.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
the errors will be gone.
@adityaparab It works, thank you.
Maybe Global Lib in wiki Stories should be updated, it does not work for bootstrap 4 beta.
@hantsy : You're welcome. :)
And it sure does need an update.. Will create an issue and raise a PR to get it fixed.
@hantsy : Submitted PR
Excited to have my first contribution in a project like angular. :) Thank you for pointing me to that wiki page.
@hantsy thx. timesaver for me!
good catch @adityaparab, it's working for me :)
Closing in favor of https://github.com/angular/angular-cli/issues/7584, which https://github.com/angular/angular-cli/pull/7586 will fix when merged. Thanks to @adityaparab 👍
i am facing similar issue #9678.Can someone check this issue pls
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.