1.7.1 version throws "Uncaught TypeError: $(...).datepicker is not a function" when bundled
See original GitHub issueExpected behaviour
datepicker should work normally as in version 1.7.0
Actual behaviour
In version 1.7.1 browser throws error
Uncaught TypeError: $(...).datepicker is not a function
Datepicker version used
1.7.1
Example code
Problem happens when code is bundled with laravel-mix (webpack).
app.js
...
require("bootstrap-datepicker")
...
used in html:
<script type="text/javascript">
$(document).ready(function(){
$('.input-daterange').datepicker({
format: 'yyyy-mm-dd',
weekStart: 1,
autoclose: true
});
});
</script>
Fix
Downgrading back to 1.7.0 helps.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Uncaught TypeError: $(...).datepicker is not a function ...
This error is occur,because the function is not defined. In my case i have called the datepicker function without including the datepicker ......
Read more >Uncaught TypeError: $(...).datepicker is not a function
Hi All,. Getting the following errors for trying get a datetime picker. Create:247 Uncaught TypeError: $(...).datepicker is not a function
Read more >"Datepicker is not a function" error thrown - Progress Community
An error with message "$(...).datepicker is not a function" is thrown when using the JQuery datepicker. Uncaught TypeError: jQuery(...).
Read more >$(...).Datepicker Is Not A Function - Jquery - Bootstrap - ADocLib
datepicker is not a function Datepicker version used 1.7.1 Example code Problem happ. 1.7.1 version throws Uncaught TypeError:. @acrobat If it were related ......
Read more >Datepicker is not defined as function - CodeProject
In the browser, check the developer tools window and see if the bootstrap-datetimepicker.min.js file is actually being found and loaded.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just ran into this exact same issue which cropped up when upgrading node >= 8 due to the differences in the way npm >= 5 manages packages. We use webpack to manage our builds and when running npm >=5 we would wind up with two different versions of jquery being loaded in our builds since we explicitly list jquery as a dependency in our project as does bootstrap-datepicker. When webpack resolves the dependencies, it sees that bootstrap-date picker has its own local dependency and loads that separately from the jquery that was previously imported. I think the real fix is to make
jquery
apeerDependency
and anyone relying on this downstream should need to includejquery
explicitly themselves as a dependency. Of course, this should be released with a major sem-version bump to prevent issues like #2206 from being filed again.I can confirm that it’s not working because
jquery
is defined independencies
but it should be inpeerDependencies
and because of that,yarn
is fetching a different version ofjquery
tonode_modules/bootstrap-datepicker/node_modules/jquery
.Version v1.7.0 (with
jquery
inpeerDependencies
) works and my recommended workaround is to keep with that version 👍