react-day-picker: unpkg usage throwing react type is invalid error
Describe the bug When I try to use react-day-picker I get the follow errors in my console
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
To Reproduce I can reproduce the error in the sandbox here -https://codesandbox.io/s/react-day-picker-base-vt99v
Expected behavior Should be able to use the react-day-picker normally
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (2 by maintainers)
This is the error I get
In the render function I have a used DayPickerInput using the wrapper component from my component library. which imports
import DayPickerInput from 'react-day-picker/DayPickerInput';
Here is the render function of the library wrapper component
In my component library rollup config, I have these plugins and commonjs with namedExports
Do I have to do any namedExports for
react-day-picker/DayPickerInput
because I cannot find any export statement in DayPicker.js or types/index.ts under node_moduels/react-day-picker.If possible can you share a snippet of your plugins in rollup.config.js
This is a nice workaround https://github.com/gpbl/react-day-picker/issues/1194#issuecomment-814065458
The issue seems to be with the export of this component, I’m not sure there’s a way to trick rollup into building it into something it’s not. If the author could export default like he did with
<DayPicker />
- it would solve the problem, I think. Using<DayPicker />
in consumer component isn’t causing any problems, commonjs plugin resolves it as a function, unlike<DayPickerInput />
in ‘index.d.ts’ add:
in your consumer component: