[BUG] DatePicker component doesn't work with Snowpack
See original GitHub issueBug Report Quick Checklist
- I am on the latest version of Snowpack & all plugins.
- I use package manager yarn.
- I run Snowpack on OS Linux.
- I run Snowpack on Node.js v12+ (v14.15.4)
Describe the bug
When trying to use the DatePicker component from react-datepicker, I get this error:
Unhandled Runtime Error
TypeError: callBind is not a function
Source
http://localhost:8080/_snowpack/pkg/object-is.v1.1.5.js [:41:26]
@http://localhost:8080/_snowpack/pkg/object-is.v1.1.5.js:41:26
To Reproduce
npx create-snowpack-app react-snowpack --template @snowpack/app-template-minimal
cd react-snowpack
yarn add react react-dom react-datepicker
rm index.js
- Create
index.jsx
with this content:
import React from 'react';
import ReactDOM from 'react-dom';
import DatePicker from 'react-datepicker';
import "react-datepicker/dist/react-datepicker.css";
ReactDOM.render(
<div>
<DatePicker />
</div>,
document.getElementById('root')
);
yarn start
- You should get the error in the browser window that opens.
Expected behavior
I expect to see the date picker which looks like a text input box and when you click on it you get a calendar to choose the date.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:8
Top Results From Across the Web
[BUG] DatePicker component doesn't work with Snowpack
I run Snowpack on Node.js v12+ (v14.15.4) Describe the bug When trying to use the DatePicker ... [BUG] DatePicker component doesn't work with...
Read more >$(...).datetimepicker is not a function - Stack Overflow
In my webpack config I use ProvidePlugin to get "jquery module". In my code I get error $(...).datetimepicker is not a function when...
Read more >antd/CHANGELOG.en-US.md - UNPKG
57, - Add `fa_IR` locale text for DatePicker, Form, Table, TimePicker and Transfer. ... 218, - Fix the misalignment issue of Image component....
Read more >module '"moment"' has no exported member 'default'.ts ... - You.com
Please describe the issue and steps to reproduce, preferably with a code sample / plunker: I've installed the pikaday datepicker that relies on...
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
I looked into this issue independently and believe that @Nivisnum is right on the money with their analysis, however I also believe that changing the value of requireReturnsDefault from ‘auto’ to ‘preferred’ is the proper fix because it would restore behavior that I don’t think was meant to be changed.
The
requireReturnsDefault
parameter was introduced in@rollup/plugin-commonjs
with version 16.0.0. snowpack changed from 15.0.0 to 16.0.0, as far as I can tell, with version 3.1.0, which is why people experiencing this issue have found a workaround in sticking with 3.0.13. This parameter added some complexity to what the plugin returns when resolving a commonjs module that has a default export. In short, the old behavior would always return the default export if it exists - the new parameter allows you to choose between that or additionally ensuring that there are no exports in addition to ‘default’. In 16.0.0, this stricter check is called ‘auto’, which the old behavior is ‘preferred’Here are the relevant bits in
@rollup/plugin-commonjs
@rollup/plugin-commonjs@16.0.0 with
requireReturnsDefault: 'auto'
(used by snowpack 3.1.0 and later)@rollup/plugin-commonjs 15.0.0 (used by snowpack 3.0.13 and before)
@rollup/plugin-commonjs@16.0.0 with
requireReturnsDefault: 'preferred'
(same behavior as 15.0.0)So by setting requireReturnsDefault to ‘preferred’, the resolution behavior will change back to what it was in snowpack in version 3.0.13 and before. I have confirmed this one line change fixes the object-is/call-bind issue for the current version of snowpack.
Now, my hunch is that this change in behavior was an unintended consequence of upgrading
@rollup/plugin-commonjs
from 15.0.0 to 16.0.0, and therefore setting requireReturnsDefault to ‘preferred’ would restore the original and intended behavior. It seems likely thatrequireReturnsDefault:'auto'
was chosen because it seems like a sensible default and without the intention of changing this behavior. If I am wrong about that, or if there are indeed cases which are fixed by this change in behavior, the only real fix is probably to expose requireReturnsDefault somehow on a per-module basis.Yeah. When I filed the bug the latest version of react-datepicker was 3.8.0 and snowpack 3.7.0 still does not work with that version. Snowpack 3.7.0 is working with the new latest version of react-datepicker which is 4.1.1.
It looks like it’s fixed because there’s no longer any
call-bind
dependency and that’s the the module with the weird exports.