Aurelia encountering an error when attempting to load Bootstrap v4 during runtime

In my aurelia.json file, I have the following configuration for bundling vendor scripts. It was directly copied from a working reference implementation and has been functioning properly.

{
  'build': {
    'bundles': [
      'name': 'vendor-bundle.js'
      'dependencies': [
        "jquery",
        {
          "name": "bootstrap",
          "path": "../node_modules/bootstrap/dist",
          "main": "js/bootstrap.min",
          "deps": ["jquery"],
          "exports": "$",
          "resources": [
            "css/bootstrap.css"
          ]
        }
      ]
    ]
  }
}

However, when attempting to upgrade to Bootstrap 4, I encountered issues. I tried updating the path in

build.bundles.dependencies[].path
to both
../jspm_packages/github/twbs/bootstrap@4.0.0-alpha6
and
../node_modules/bootstrap-v4-dev/dist
, but it did not resolve the runtime error. Even copying v4 files to the v3 dist folder did not help.

The build process is successful; however, the issue appears during run-time:

DEBUG [templating] importing resources for app.html
Uncaught TypeError: plugin.load is not a function
Unhandled rejection Error: Failed loading required CSS file: bootstrap/css/bootstrap.css

UPDATE:

Following Ashley Grant's suggestion, I updated Bootstrap via NPM without making changes to aurelia.json. The error persisted, suggesting a bug. However, others have successfully migrated with the same toolchain.

UPDATE 2:

I have outlined steps to recreate the issue:

$ au new
name  # any valid value
2     # Select TypeScript as the language
1     # Create project structure
1     # Install dependencies

Navigate to the project directory.

Add the specified entries to build.bundles[1].dependencies in aurelia_project/aurelia.json

$ npm install jquery --save
$ npm install bootstrap@^4.0.0-beta --save

Update src/app.html to include:

<template>
  <require from="bootstrap/css/bootstrap.css"></require>
</template>

Finally, run either of the following commands and access the URL provided:

$ au run

OR

$ au build
$ serve

The described errors are observed in Google Chrome and Mozilla Firefox on Arch Linux systems. Testing on other systems has not yet occurred.

UPDATE 3:

Following @vidriduch's advice, everything seems to be functional. Still, the console displays:

Uncaught SyntaxError: Unexpected token export
vendor-bundle.js:3927 Uncaught Error: Mismatched anonymous define() module: [entirety of vendor-bundle.js printed here]

These messages appear initially upon page load in debug mode, but no further errors surface.

Answer №1

You have encountered an issue with the Bootstrap 4.0.0-beta version due to a missing popper.js dependency. To resolve this, you can add the following line in the prepend section of your aurelia.json file for Aurelia:

"node_modules/popper.js/dist/umd/popper.js"

If you are using RequireJS, follow this suggestion from @hxtk. For webpack users, check out Bootstrap's documentation on webpack dependency linking at https://getbootstrap.com/docs/4.0/getting-started/webpack/.

Note that you need to install popper.js version 1.11.0, as discussed here: https://github.com/twbs/bootstrap/issues/23381. To do so, run:

npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c7c637c7c697e22667f4c3d223d3d223c">[email protected]</a>

or

yarn add <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="50203f202035227e3a2310617e61617e60">[email protected]</a>

After completing these steps, everything should be functioning correctly :)

Answer №2

It seems like your configuration in aurelia.json is correct. However, it appears that you may have missed running

npm install bootstrap@^4.0.0-beta --save
since you mentioned copying files into a versioned node_modules folder. Unlike JSPM, NPM doesn't use versioned folders.

I recommend running

npm install bootstrap@^4.0.0-beta --save
to resolve the issue. I've successfully implemented this exact configuration for one of my clients before.

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

Height Setting for Angular Material Buttons

html: <body id="app"> <md-button> Yo </md-button> </body> Looks: Why is the button set to 100% height? It should look like an inline element according to the materials documentation here. Also, why aren't the materi ...

Learn how to properly configure the React useState hook within the useEffect function and in combination with the

I am currently encountering an issue with my code. At the initial page load, the program checks for an available agent and sets the setDefault state variable to true if an agent is available. Then, if a language change event occurs and there is an availabl ...

React Native buttons are displaying at a fixed width and not adjusting as expected

Within a row, I have two buttons with a padding of 20 between them, and they are only taking up the necessary width for the button text. The width remains constant! Here is the code for the buttons: <View style={styles.buttonContainer}> &l ...

The browser encountered an issue trying to load a resource from a directory with multiple nested levels

I've stumbled upon an unusual issue. Here is a snapshot from the inspector tools. The browser is unable to load certain resources even though they do exist. When I try to access the URL in another tab, the resource loads successfully. URLs in the i ...

Responsive Bootstrap navigation bar with a prominent logo

I am currently working on creating a navigation bar with logo following two different layouts. The first layout should be centered vertically and look like this on desktop: Desktop Layout For mobile devices, the layout should resemble this design: Mobile ...

Executing an AJAX request to insert data into MySQL

After my extensive online search, I came across a solution that involves using ajax to set information in my database. While browsing through this page, I learned how to retrieve data from the database. My specific query is: can we also use ajax to set in ...

What is the process of transferring information from one window to another window?

Is there a way to transfer data between two windows? In my parent window, I have a button that redirects to another page with a success button. When the success button is clicked on the child window, I want to display "success" text on the parent window. ...

Utilizing jQuery's AJAX method for Access-Control-Allow-Origin

Here's the code snippet I'm working with: $.ajax({ url: url, headers: { 'Access-Control-Allow-Origin': '*' }, crossDomain: true, success: function () { alert('it works') }, erro ...

Modifying a value within a loop

var currentmix = document.getElementById('custommix').value.split(","); var additionalcost = 0; for (i = 0; i < currentmix.length; i++) { if (currentmix[i] != "") { var mixinpriceid = "mixinprice"+c ...

Looking for assistance with navigating through this URL using Python (requests, beautifulsoup, or selenium) or Javascript (node js, puppeteer)?

While attempting to gather data, I encountered an interesting pagination challenge on the following URL: My expertise in Web Scraping was put to the test as this website implemented a unique JavaScript-driven pagination. For the initial 5 pages, it simply ...

Prevent event bubbling on a link generated by an Angular directive that includes transclusion

I am currently developing a directive that adds a link to a DIV element through transclusion. However, I am facing an issue where I want to execute specific functionality when the link is clicked without being redirected to the dummy href (in this case goo ...

Switch directions following a successful status code of 200

After successfully logging in (with a status of 200), I want to change my route to /expenses. async SendLogin() { const response = await axios.post("api/auth/login", { email: this.email, password: this.password, }); localStorage.setItem("toke ...

setInterval versus delay

I am attempting to create a div that bounces every 4 seconds, then fades out after 15 seconds. However, the current code isn't working as expected - the div disappears and the bounce effect doesn't occur. $(document).ready(function(){ functi ...

JavaScript implementation for universal zoom functionality across all web browsers

I am working on a graph created with simple <div> elements and I am looking for a way to allow users to zoom in and out. It appears that the css zoom property, which is effective in Internet Explorer, does not work well or consistently in other brows ...

Applying jQuery to deactivate blank categories within a sorted directory

I'm in the early stages of learning Javascript/jQuery. I have a list of items (specifically, course offerings) arranged in a UL. Each "course" is represented by an LI element. The list is filtered by categories using jQuery, which controls the visibil ...

What distinguishes defining a function through a prototype versus as a class property?

Check out this code snippet: Apple defines its function using a prototype. Banana defines its function using a class property. var Apple = function(){} Apple.prototype.say = function(){ console.debug('HelloWorld'); } var Banana = functio ...

Exploring ways to incorporate or eliminate animations on mobile devices using html/css

Is it possible to control animations on different devices using media queries? For example, can you show an animation only on mobile devices while hiding it on desktop or laptop? Conversely, is there a way to add an animation specifically for mobile device ...

I am facing issues with my Bootstrap and CSS conflicting with each other in React JS

My styles are mysteriously changing when I add the bootstrap link between the <head></head> tags. Here is the header without the bootstrap link: https://i.sstatic.net/ly2nf.png And here is the header with the bootstrap link: https://i.sstatic ...

When trying to retrieve a value from a custom render function in React with TypeScript, an error occurs indicating that the value is not assignable to type 'ReactNode'

Recently, I attempted to develop a versatile swiper component using Next.js 13 (App Router) v13.4.12 along with TypeScript. However, I encountered an issue when trying to access data from the component props, which involves a custom function for rendering ...

Functions properly in JSFiddle, but fails in the browser even when surrounded by a document ready handler

I am struggling with printing a 16x16 grid of divs using jQuery. It works perfectly on JSFiddle, but only one row is printed when testing in the browser. I realized that changing the jQuery version from edge to 2.1.3 on JSFiddle results in the same issue i ...