Symphony 5 and Encore: Issue with Bootstrap JS Loading

Encountering issues while trying to integrate Bootstrap's js with Symfony 5, encore, stimulus, etc...

All required dependencies like jquery, popper, corejs are installed and functioning, except for Bootstrap's JS components.

The compilation of app.scss and app.js seems to be successful using sass, postcss, babel, including Bootstrap's CSS. However, the dropdowns and other JS functionalities from Bootstrap are not working.

assets/app.js

// Import any CSS to output into a single css file (app.css)
import './styles/app.scss';

// Initialize the Stimulus application
import './bootstrap';

assets/bootstrap.js

import { startStimulusApp } from '@symfony/stimulus-bridge';

// Register Stimulus controllers from controllers.json and in the controllers/ directory
 export const app = startStimulusApp(require.context(
    '@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
    true,
    /\.(j|t)sx?$/
));

// Register custom, 3rd party controllers here
// app.register('some_controller_name', SomeImportedController);

Note: No specific controller found under assets/controllers

webpack.config.js

const Encore = require('@symfony/webpack-encore');

// Manually configure the runtime environment if not already configured by the "encore" command.
// Useful when using tools relying on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}

Encore
  .setOutputPath("public/build/")
  .setPublicPath("/build")
  
  // Define entry points for JavaScript and CSS files
  .addEntry("app", "./assets/app.js")
  .enableStimulusBridge('./assets/controllers.json')
  
  .splitEntryChunks()
  .enableSingleRuntimeChunk()
  
  // Additional feature configurations
  .cleanupOutputBeforeBuild()
  .enableBuildNotifications()
  .enableSourceMaps(!Encore.isProduction())
  .enableVersioning(Encore.isProduction())

  .configureBabel((config) => {
    config.plugins.push("@babel/plugin-proposal-class-properties");
  })
  
  .configureBabelPresetEnv((config) => {
    config.useBuiltIns = "usage";
    config.corejs = 3;
  })

  .enableSassLoader()
  .enablePostCssLoader();

module.exports = Encore.getWebpackConfig();

package.json (only dependencies)

  "devDependencies": {
    "@popperjs/core": "^2.10.2",
    "@symfony/stimulus-bridge": "^2.1.0",
    "@symfony/webpack-encore": "^1.6.1",
    "autoprefixer": "^10.4.0",
    "bootstrap": "^5.1.3",
    "core-js": "^3.19.1",
    "jquery": "^3.6.0",
    "postcss-loader": "^6.2.0",
    "sass": "^1.43.4",
    "sass-loader": "^12.3.0",
    "stimulus": "^2.0.0",
    "webpack-notifier": "^1.14.1"
  },
  "dependencies": {
    "popper.js": "^1.16.1"
  }

Looking to troubleshoot these issues further? Reach out for more insights!

Answer №1

There is no bootstrap import in your code. Even though you have a file called bootstrap.js, it seems to be handling different stimulus tasks.

To resolve this, make sure to include import 'bootstrap'; in your app.js file.

Answer №2

Make sure you are importing the correct version. The proper import statement should be: import './bootstrap';, as opposed to using import 'boostrap'; which imports the getbootstrap library.

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

Implementing JavaScript to showcase a list extracted from an API dataset

I'm currently undertaking a project where I am integrating an API from a specific website onto my own webpage. { "data": [{ "truckplanNo":"TCTTV___0D010013", "truckplanType":"COLLECTION", " ...

Avoid using the JavaScript 'Sys.WebForms..' function if there is no ScriptManager present on the page

Currently, I am using a single JavaScript binding in the Master Page for my entire project. However, the Master Page does not include a ScriptManager. This means that some pages have Ajax components, such as UpdatePanel, while others do not. The 'Sys. ...

Obtaining a File type object from a URL (specifically an image) in Vue.js

Suppose I have an image URL like http://localhost/sample.jpg. What is the best way to save this image URL into a File object using native JavaScript API in my component? export default { created () { const imageUrl = 'http://localhost/sample.jpg ...

Ajax displays JSON data within an array format

Looking for a solution where I have MySQL data displayed in a table, with each row having a button. When the button is clicked, a bootstrap modal should appear containing that data. I have converted the MySQL data to JSON format and assigned the ".view_dat ...

Code executing twice instead of once in Javascript

Having trouble with a script in my demo below. When I enter "first input", submit, then click on the returned "first input", it alerts once as intended. However, upon refresh, if I enter "first input", submit, then add "second input", submit, and finally c ...

Looking to extract the first URL from a string using JavaScript (Node.js)?

Can someone help me figure out how to extract the first URL from a string in Node.js? " <p> You left when I believed you would stay. You left my side when i needed you the most</p>**<img src="https://cloud-image.domain-name.com/st ...

Encountering connectivity issues with MongoDB client and struggling to insert data while utilizing promises

Currently, I am experimenting with nodeJS and encountering an error when trying to establish a connection to the MongoDB Client. I have implemented promises for improved readability but am facing issues connecting. The code involves connecting to the datab ...

Developing a Symfony2 form collection containing entities with a one-to-one relationship

Have you ever encountered a situation where a form contains a collection of entities with one-to-one relationships? I have an entity that has multiple addresses, each of which has a one-to-one relationship with another entity. I'm running into issues ...

Ways to access information from a SQLite database using Angular

I am a beginner in front-end/back-end communication and I need guidance on how to retrieve data from a SQLite db file to populate a page in my Angular project. I have no idea where to begin, so any resources you can recommend would be greatly appreciated. ...

The Angular filter is failing to display the category value

My issue lies in adding a filter to display categories, as my setCurrentCategory function is not showing any value but instead displaying 'undefined'. The goal is to show the category for each person. I'm using ng-click to pass to my functio ...

`Is there a way to retrieve the ID of an element upon clicking on it?`

Can you help me with a JavaScript query? I have two HTML div elements with ids of 'div1' and 'div2'. When I click on any of the divs, I want to display the id of the clicked div. Any thoughts? <div id="div1"></div> <div ...

Next.js is throwing a TypeError because it does not recognize the function fs.readFileSync

In my JSON data file called total.json, I store information for a chatbot. { "guilds": 3, "users": 21 } Within my index.tsx file, I want to display this data on the webpage, so I attempt the following: import fs from 'fs'; f ...

Encountering an error when attempting to parse a JSON Object in Java from an AJAX call

** Latest Code Update ** My JavaScript and Ajax Implementation: $(function() { $("#create_obd").bind("click", function(event) { var soNumber = []; $('#sales_order_lineItems input[type=checkbox]:checked').eac ...

The render function is not being executed due to a disruption in the code flow

Within the given code snippet, there is a peculiar issue with the render function being called inside the loop below. Strangely, the console.log statement before the function call executes successfully, but the one directly inside the function does not s ...

React: Remove a particular row from the table

I am currently working on a project that involves building a table component. Each row in this table is also a separate component. class FormulaBuilder extends Component { constructor(props) { super(props); this.state = ...

Design your very own personalized Show Layout component

Currently, I'm in the process of creating a unique layout component to enhance the design of my Show page. I've encountered some inconsistencies with functionality, and my solution involves utilizing the Material-UI <Grid> component. While ...

Trouble with loading images on hbs/nodejs

I'm currently working on a web application using NodeJs and express-handlebars. However, I am facing an issue with images not displaying correctly on the HTML page that is being rendered using handlebars. Here is the structure of my app: The root fo ...

Is there a script available on this page that allows me to access the Google Chrome plug-in variable?

Could you kindly clarify if a script on the webpage is able to access variables from a Chrome extension? I have developed an extension for Google Chrome and am concerned about the possibility of the website owner where the extension is running being able ...

Executing multiple HTTPS requests within an Express route in a Node.js application

1 I need help with a route that looks like this: router.get('/test', async(req, res)=>{ }); In the past, I have been using the request module to make http calls. However, now I am trying to make multiple http calls and merge the responses ...

Is there a foolproof way to determine when a dialogue box pops up on

I'm currently building an electron app using vue and Vuetify. I am able to create a modal using dialog, but I want to be able to modify certain elements within the dialog after it is displayed. When using $refs, I cannot find the element before the d ...