bootstrap-datepicker icon indicating copy to clipboard operation
bootstrap-datepicker copied to clipboard

1.7.1 version throws "Uncaught TypeError: $(...).datepicker is not a function" when bundled

Open ipa1981 opened this issue 7 years ago • 11 comments

Expected 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.

ipa1981 avatar Jul 12 '17 07:07 ipa1981

@andreypopp @Mithgol is it possible this is related to the dependency on jquery in dependencies/peer-dependencies?

acrobat avatar Jul 12 '17 07:07 acrobat

@ipa1981 did it work on 1.6.4?

acrobat avatar Jul 12 '17 08:07 acrobat

@acrobat Yes, 1.6.4 works as well.. Problem is relevant to 1.7.1 only.

ipa1981 avatar Jul 12 '17 13:07 ipa1981

@acrobat If it were related to the dependencies / peerDependencies, than 1.7.0 would be broken and 1.7.1 would work again because b56efd6153a9fd3e46df0c911e204bd8af14dddc reverts 84e96f469dd53484d04163a20722c85b30bf4324 right? Therefore it's probably something else.

Mithgol avatar Jul 26 '17 19:07 Mithgol

Is there a fix for this yet? If not, how do I get v1.7.0 since apparently that works. Never mind, my fault, permissions were wrong on the datepicker.js file.

lcsqlpete avatar Aug 03 '17 01:08 lcsqlpete

I can confirm that it's not working because jquery is defined in dependencies but it should be in peerDependencies and because of that, yarn is fetching a different version of jquery to node_modules/bootstrap-datepicker/node_modules/jquery.

Version v1.7.0 (with jquery in peerDependencies) works and my recommended workaround is to keep with that version :+1:

arutkowski00 avatar Oct 09 '17 10:10 arutkowski00

Please check #2163 for the reasons of reverting. I don't know what is best or what we should do, so please help use fixing this issue without breaking the original issue of #2163. Thanks!

acrobat avatar Oct 09 '17 13:10 acrobat

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 a peerDependency and anyone relying on this downstream should need to include jquery 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.

jleider avatar Mar 23 '18 18:03 jleider

Resolved?

gabrielferreiraa avatar Mar 10 '20 16:03 gabrielferreiraa

Hey, I use Webpack and it seems I have the exact same issue with version > 1.7.0 :/

Do you know what to do to fix it so I could open a PR eventually ? Thanks

guillaumebriday avatar Jun 02 '20 08:06 guillaumebriday

We have the same issue with 3.7.1 ('is not a function') vs. 3.7.0 (works).

burithetech avatar Oct 13 '23 08:10 burithetech