popper.js in bootstrap 4 gives SyntaxError Unexpected token export
Asked Answered
D

6

120

I tried install bootstrap 4, and included following links

<script src="libs/jquery/dist/jquery.min.js"></script>
<script src="libs/tether/dist/js/tether.min.js" ></script>
<script src="libs/popper.js/dist/popper.js"></script>
<script src="libs/bootstrap/dist/js/bootstrap.min.js" ></script>

But The following error occurs :

Uncaught syntaxError: Unexpected token export

enter image description here

Any ideas how to fix it?

Dichloride answered 28/9, 2017 at 1:55 Comment(14)
I do not know, bootstrap file requires itNorty
no I have used bootstrap but it never asked to meSchramm
last version askedNorty
well If it is so then I will tell use CDN linksSchramm
the proble is that I'm not supposed to use CDN links when uploud on marketNorty
moreover, I tried it now, but it does not helpedNorty
just shift proper js line before the bootstrap js and tell meSchramm
still gives the same errorNorty
getbootstrap.com/docs/4.0/getting-started/introduction/… try this out it may help youSchramm
there may can be some error in file or in linking it...and remember adding pooper js before bootstrap jsSchramm
If you pay attention to my question, then you will see that I added popper before bootstrap fileNorty
Possible duplicate of How to use popper 1.12.0 with bootstrap 4.0 betaAnu
I'don't know if it is useful but here there is a solution: #45695311Exhaust
Yes, latest version requires it. I was fine without it using standard bootstrap types, but then happened when i tried to do bootstrap drop down.Faina
D
45

I encountered the same issue if I use popper.js from CDN network like cdnjs.

If you observe the source code of Bootstrap 4 examples like for example Navbar you can see that popper.min.js is loaded from:

<script src="https://getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js"></script>

I included that in my project and the error is gone. You can download the source code from

https://getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js

and include in your project as a local file and it should work.

Distance answered 28/9, 2017 at 2:38 Comment(6)
yes. You are right. I did copy and paste that code and the error disappears. The CDN does not specify any specific version of popper.jsMensurable
Although it works, I think this is not the proper way, until BootStrap team updates its own code.Sivie
The above URL returns a not found error (404). I used getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js for Bootstrap 4.1.3 and this resolved the problem for me.Stowell
Using the technique suggested in this answer is like chasing a moving target. Right answer is provided by Marc and Zim.Boabdil
unfortunately this does not work anymore. The error is gone, but the tooltip is the default HTML tooltipDingman
CDN links are often treated like a silver bullet for these kind of things, but oftentimes the answer is that you just need to use a different .js file in the downloaded folder. In this case, it's the UMD version of the folder you need, as Marc and Zim point out.Zwickau
B
295

Just got this too and figured why it really happens. In case others get by here:

Check the readme.md "Usage". The lib is available in three version for three difference module loaders. In short: if you load it with the <script> tag then you must use the UMD version. You can find it in /dist/umd. The default (in /dist) is the ESNext (ECMA-Script) which can not be loaded using the script tag.

Beckham answered 29/1, 2018 at 9:32 Comment(5)
Thank you. Got rid of the error for me by changing to the umd file.Trinl
Changing the reference to the file under umd folder solved my issuePratique
This should have been accepted answer. Awesome. Thanks so much for sharing.Meatman
Awesome for the fast help, thanks. I was wondering what this /umd and /esm folders are but Google does not give good results.Turbulent
Though this sounds like a Thanks, me too answer, Please let me add, @Beckham you are a lifesaver. My developers spent a good 3 days with this issue hanging fire on low priority. It got escalated to my care and here we are. Resolved in 3 minutes flat. Let me add, we truly do stand on the shoulders of Giants.Batty
K
106

Bootstrap 4 requires the UMD version of popper.js, and make sure the order is as follows:

<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="~/Scripts/jquery-3.0.0.min.js"></script>
<script src="~/Scripts/umd/popper.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
Kingbolt answered 9/4, 2018 at 14:39 Comment(2)
The UMD version is the only CDN link that removed the error.Contemplate
Thanks mate! Your ordering fixed my issue. Cheers!Frostbite
D
45

I encountered the same issue if I use popper.js from CDN network like cdnjs.

If you observe the source code of Bootstrap 4 examples like for example Navbar you can see that popper.min.js is loaded from:

<script src="https://getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js"></script>

I included that in my project and the error is gone. You can download the source code from

https://getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js

and include in your project as a local file and it should work.

Distance answered 28/9, 2017 at 2:38 Comment(6)
yes. You are right. I did copy and paste that code and the error disappears. The CDN does not specify any specific version of popper.jsMensurable
Although it works, I think this is not the proper way, until BootStrap team updates its own code.Sivie
The above URL returns a not found error (404). I used getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js for Bootstrap 4.1.3 and this resolved the problem for me.Stowell
Using the technique suggested in this answer is like chasing a moving target. Right answer is provided by Marc and Zim.Boabdil
unfortunately this does not work anymore. The error is gone, but the tooltip is the default HTML tooltipDingman
CDN links are often treated like a silver bullet for these kind of things, but oftentimes the answer is that you just need to use a different .js file in the downloaded folder. In this case, it's the UMD version of the folder you need, as Marc and Zim point out.Zwickau
R
22

You can also add bootstrap.bundle.min.js and remove popper.js in your html.

Bundled JS files (bootstrap.bundle.js and minified bootstrap.bundle.min.js) include [Popper](https://popper.js.org/), but not jQuery.

Rescission answered 20/2, 2019 at 5:22 Comment(3)
bootstrap.bundle.min.js included popperjsGoodhen
best answer since it doesn't require use of additional Popper.js library at allCoffeepot
BEST ANSWER, THANKSTomblin
C
12

Line 96 in README

Dist targets

Popper.js is currently shipped with 3 targets in mind: UMD, ESM and ESNext.

  • UMD - Universal Module Definition: AMD, RequireJS and globals;
  • ESM - ES Modules: For webpack/Rollup or browser supporting the spec;
  • ESNext: Available in dist/, can be used with webpack and babel-preset-env;

Make sure to use the right one for your needs. If you want to import it with a <script> tag, use UMD.

Cy answered 21/10, 2019 at 18:51 Comment(1)
Using the popper.min.js file located in the UMD directory resolved my issued when installing popper via npm. Thank you!Hellhole
A
6

You have following code in Bundle Config bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                    "~/Scripts/umd/popper.min.js",
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

following code in layout html

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")

This worked for me

Aret answered 13/6, 2018 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.