The error of "Unexpected token export" arises in bootstrap 4 when using popper.js

I attempted to install Bootstrap 4, and added these 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>

However, I encountered the following error :

Uncaught syntaxError: Unexpected token export

https://i.sstatic.net/42loV.png

Does anyone have any suggestions on how to resolve this issue?

Answer №1

Recently encountered this issue and found the solution. Here's how to resolve it:

If you're facing a problem with loading, refer to the readme.md file under "Usage". Depending on your module loader, there are three versions of the library available. If you're using the <script> tag for loading, make sure to use the UMD version located in /dist/umd. The default version found in /dist is ESNext (ECMA-Script) which cannot be loaded with the script tag.

Answer №2

To utilize Bootstrap 4, you must include the UMD version of popper.js in the correct order:

<!-- First, load jQuery, followed by Popper.js, and finally 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>

Answer №3

Encountering the same problem when using popper.js from a CDN like cdnjs.

If you check out the source code of various Bootstrap 4 examples, such as the Navbar, you'll notice that they load popper.min.js from:

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

I added that to my project and the issue disappeared. You can also grab the source code from

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

And include it in your project as a local file. This should resolve the problem.

Answer №4

Incorporating bootstrap.bundle.min.js instead of popper.js can streamline your HTML code.

The packaged JS files, specifically bootstrap.bundle.js and the compressed bootstrap.bundle.min.js, come equipped with Popper (visit for more information), but do not include jQuery (jQuery).

Answer №5

Step 96 in the README document

Available Distribution Targets

The Popper.js library is designed to be compatible with three main distribution targets: UMD, ESM, and ESNext.

  • UMD - Universal Module Definition: Suitable for AMD, RequireJS, and global usage;
  • ESM - ES Modules: Intended for use with webpack/Rollup or browsers that support this specification;
  • ESNext: Found in the dist/ directory, can be utilized with webpack along with babel-preset-env;

It is important to select the appropriate target based on your requirements. If you plan to import using a <script> tag, opt for UMD.

Answer №6

Below is the code snippet found in your Bundle Config:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        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"));

The following code can be seen in the layout HTML:

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

This implementation was successful for me!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create the correct structure for an AWS S3 bucket

My list consists of paths or locations that mirror the contents found in an AWS S3 bucket: const keysS3 = [ 'platform-tests/', 'platform-tests/datasets/', 'platform-tests/datasets/ra ...

Node.js, sigma.js, and the typescript environment do not have a defined window

When attempting to set up a sigma.js project with node.js in TypeScript, I encountered a reference error after starting the node.js server: ts-node index.ts The problem seems to be located within the sigma\utils\index.js file. <nodejsproject& ...

Discovering common elements in various arrays of objects

Details: record1 = [{"site": "The Blue Tiger", "zipcode": "E1 6QE"}, {"site": "Cafe Deluxe", "zipcode": "E6 5FD"}] record2 = [{"site": "Blue Tiger", "zi ...

Display the sprite and PlaneGeometry image from three.js in full size regardless of their dimensions

My goal is to display the image in its entirety regardless of size. var src1 = "https://i.imgur.com/C9lWPeL.jpg", src2 = "https://i.imgur.com/a9zyCRt.jpg"; const src = src1; var scene = new THREE.Scene(); var loader = new THREE.TextureLoader(); load ...

Using Node.js to insert JSON data into a MySQL table

In my database, I have a table called users with the following fields: id, name (varchar), and gallery (json). The gallery field contains the image paths of user-uploaded rows. Users can add more images to their gallery, and each image path is stored in ...

What strategies can be employed to maintain reliable datetime management for a reservation system operating in diverse time zones?

Looking at the big picture: An interesting scenario arises when a hotel owner specifies a time frame for booking reservations at a restaurant (5pm - 10pm). Along with this information, there is also a timezone provided to ensure that dates are displayed i ...

Is there a more effective method to return a response apart from using a redundant function?

function unnecessaryFunction(){ let details: SignInDetails = { user: user, account: account, company: company }; return details; } I am being told that the details value is unnecessary. Is there ...

JavaScript Calendar and Clock Selector

I've been scouring every corner of the internet, but I can't seem to locate what I'm after. My quest is for a basic Date and time picker along with a standalone time picker that harnesses the power of JavaScript. My webpage is built using ...

Best method for reverting react-native to previous version

Here's the dilemma I'm facing: I had a functional version of a react-native project that was running smoothly and committed to my git repository. Deciding to upgrade from react-native 0.26.3 to 0.28 led me into a tangled web of dependencies, so ...

Unable to customize the color of span elements used for ASP validation in .NET Core MVC

I am having trouble changing the color of the error message that appears when something goes wrong using "span asp-validation-for=". Even though I have added the class="text-danger", the color remains black. I am using Bootstrap and it is working fine. I ...

At what point does a JavaScript script element officially begin its loading process?

Consider this basic function: let f = ()=> { let myScript=document.createElement("script"); myScript.src="otherFile.js"; alert(x); x=2; alert(x); } Now, the content of otherFile.js is as follows: x=3; If we assume that x ...

"Discovering the steps to preview a file that has been uploaded using Angular

I am currently working with Angular File Upload. http://plnkr.co/edit/qLckEIlNLEcIfvwn4Q5x?p=preview I'm looking to implement an upload-preview feature when a file is uploaded. Can anyone provide any suggestions or guidance? Below is the HTML code s ...

MongoJS Node findOne query inaccurately returns empty result set

Utilizing MongoJS: https://github.com/mafintosh/mongojs Retrieves all data Returns an empty array</p> The database contains the data I am looking for. I've also tried searching using a different key (such as name). Why is it unable to locate ...

"Utilize the addEventListener function in combination with the 'for' keyword to

I have been working on a Chrome extension where I use a "for" loop to change the display style of elements named "mode" to none, except for one which should be displayed at the end of the loop. However, whenever I click on the button to activate it, my tab ...

jQuery AJAX encountering parsing error when retrieving data from Laravel controller

I'm attempting to retrieve data from a laravel controller using 'jquery' ajax, but I keep encountering the 'parsererror'. According to the laravel documentation, it automatically sets the header Content-Type= 'application/json ...

Customize Bootstrap styling based on screen size changes

I am curious to learn how I can adjust the CSS of my website in Bootstrap based on different screen sizes. I want to change text sizes and images, but I'm unsure about how to do it. Thank you for any guidance. Here is a snippet of my code: <!DOCT ...

Provide a boolean value of true or false to indicate whether all delete operations were successfully completed

Currently, I am using Sequelize, GraphQL, and Typescript for my coding. Within my database, I have two tables named RecordInformation and OtherDescription. The RecordInformation table contains a foreign key called "OtherID" which references the OtherDescri ...

Arrange form elements with Bootstrap 5 styling

Seeking assistance with creating a mobile login page using Bootstrap 5 and custom CSS. Struggling to align form items inside the form properly. Any suggestions on how to achieve this? .row { height: 100vh; justify-content: center; align-items: cen ...

Incorporate a PHP-generated array into JavaScript

I'm currently working on implementing a JavaScript slideshow on my index page. Rather than having a static array, I'd like to dynamically build the array using PHP and then include it in the script. However, I'm not sure how to go about this ...

Parsing error in Vue.js eslint: encountering an unexpected token

Having trouble with an error in the state.js file (at => in the const profile), not sure what's causing it. Any feedback would be appreciated. const credentials = { email: '', password: '' } const profile = { => userI ...