Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot set properties of undefined (setting 'BootstrapTable') #7167

Open
ahmedtoolapp opened this issue Jan 24, 2024 · 6 comments
Labels
awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. Bug Issues which are marked as Bug

Comments

@ahmedtoolapp
Copy link

Bootstraptable version(s) affected

1.22.2

Description

Hello,

I'm used to using this plugin, but this time I'm stuck on the first use.
I installed latest version of jQuery 3.7.1 and latest version of Bootstrap 5.3.2 and latest version of Bootstrap-table 1.22.2

All this in a new symfony 6 project with a new installation of webpack 5.74.0, node v21.1.0 and npm

in my app.js file I did:
const $ = require('jquery');
require('bootstrap');
import 'bootstrap-table/dist/bootstrap-table.js';
import 'bootstrap-table/dist/locale/bootstrap-table-fr-FR.js';

and in my js file
const table = $("#table");
Table.bootstrapTable(....)

First thing I got the message
Uncaught TypeError: Cannot set properties of undefined (setting 'BootstrapTable')

I tried to modify how to import jQuery and bootstrap
import jQuery from 'jquery'
window.jQuery = jQuery
window.bootstrap = require('bootstrap');

Unfortunately it doesn't change anything, I tried to use the cdn directly in the base html file, I no longer have the error but in the js file where I declare the table I have the message:
bootstrap is not a function

any ideas why it doesn't work please

Example(s)

app.js

const $ = require('jquery');
require('bootstrap');
import 'bootstrap-table/dist/bootstrap-table.js';
`import 'bootstrap-table/dist/locale/bootstrap-table-fr-FR.js';

file.js
const table = $("#table");
const data = [ { 'id': 0, 'name': 'Item 0', 'price': '$0' }, { 'id': 1, 'name': 'Item 1', 'price': '$1' }, { 'id': 2, 'name': 'Item 2', 'price': '$2' }, { 'id': 3, 'name': 'Item 3', 'price': '$3' }, { 'id': 4, 'name': 'Item 4', 'price': '$4' }, { 'id': 5, 'name': 'Item 5', 'price': '$5' } ]
table.bootstrapTable({data: data})
`

Possible Solutions

No response

Additional Context

Symfony 6 / php 8.2.15
"webpack": "^5.74.0",
symfony/webpack-encore": "^4.5.0"
bootstrap": "^5.3.2"
bootstrap-table": "^1.22.2",
jquery": "^3.7.1",

Node : v21.1.0
npm 10.2.0

@ahmedtoolapp ahmedtoolapp added the Bug Issues which are marked as Bug label Jan 24, 2024
@ahmedtoolapp
Copy link
Author

UP

@ahmedtoolapp
Copy link
Author

Try to find a solution for my problem
I only succeeded when downgrading to the version 1.21.2

This still a bug for me until someone have any idea.

@wenzhixin
Copy link
Owner

You can check out our webpack starter example: https://github.com/wenzhixin/bootstrap-table-examples/tree/develop/webpack-starter.

@wenzhixin wenzhixin added the awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. label Jan 28, 2024
@bplatypus
Copy link

bplatypus commented Feb 13, 2024

I also think this is a bug. Had the exact same error "Uncaught TypeError: Cannot set properties of undefined (setting 'BootstrapTable')", but with some different stack. I just figured out how to make it work after quite some hours struggling yesterday.

I'm using:
vitejs
jquery
bootstrap-table

I'm using vite.config.js to inject jquery, so I had this (which is NOT working after build):

> import { defineConfig } from 'vite'
> import inject from '@rollup/plugin-inject';
> 
> export default defineConfig({
>     build: {
>         outDir: './../../output/web',
>         minify: true
>     },
>     plugins: [
>         inject({
>             $: 'jquery',
>             jQuery: 'jquery'
>         })
>     ]
> })

and in the '.js' file which is using bootstrap-table, I had the standard imports:

> import 'bootstrap'
> import 'bootstrap-table' 

This is working OK if I run 'npm run dev' BUT when I was building the project using 'npm run build', I started to get this "Uncaught TypeError: Cannot set properties of undefined (setting 'BootstrapTable')" error.

Solution for me was

  1. Remove

jQuery: 'jquery'

from the 'vite.config.js'

  1. Remove the imports from the '.js' file where bootstrap-table was used
  2. Put the imports in the main.js
  3. AFTER 'bootstrap' imports, add

window.jQuery = $

To resume, my 'vite.config.js' is now like this:

> import { defineConfig } from 'vite'
> import inject from '@rollup/plugin-inject';
> 
> export default defineConfig({
>     build: {
>         outDir: './../../output/web',
>         minify: true
>     },
>     plugins: [
>         inject({
>             $: 'jquery'
>         })
>     ]
> })

And my main.js:

> import 'bootstrap'
> import 'bootstrap-table'
> 
> window.jQuery = $

And NO other 'bootstrap' imports in my '.js' file.

edit: I also tried to inject bootstrap in vite.config.js, but this was not working either.

@wenzhixin
Copy link
Owner

Have you solved your problem?

@trandbert37
Copy link

Same problem for me with Webpack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. Bug Issues which are marked as Bug
Projects
None yet
Development

No branches or pull requests

4 participants