Using Select2 with npm / webpack resolves in JS Error "Cannot read properties of undefined (reading 'getAttribute') at Object.Utils.GetUniqueElementId"
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 25.9k
- Forks
- 6.1k
- Avg merge
- 8d 53m
- Merged PRs (30d)
- 4
Description
I installed Select2 with npm and use webpack to bundle the JS files.
My JS Code is as follows:
let select2 = require("select2")
$(window).load(function () {
$('select').each( function() {
$(this).select2();
})
})
Im not sure if im importing / require select2 wrong but even if i do:
import select2 from "select2"
I am getting the following JS Error:
Uncaught TypeError: Cannot read properties of undefined (reading 'getAttribute')
at Object.Utils.GetUniqueElementId (app.js?ver=1.0.0:12182:29)
at Object.Utils.GetData (app.js?ver=1.0.0:12217:20)
at Select2 (app.js?ver=1.0.0:16939:15)
at Module../resources/js/public_app.js (app.js?ver=1.0.0:19:94)
at __webpack_require__ (app.js?ver=1.0.0:32890:42)
at app.js?ver=1.0.0:33032:87
at Function.__webpack_require__.O (app.js?ver=1.0.0:32924:23)
at app.js?ver=1.0.0:33035:53
at app.js?ver=1.0.0:33037:12
It seems like something is missing / wrong. jQuery is globally available.
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported npm/webpack setup using the shown require or import code and the stack trace at Utils.GetUniqueElementId. Inspect Select2's initialization path and confirm whether the select elements are available when select2 is called. Done means the example initializes the select elements without the getAttribute error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, jquery, webpack
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100