I installed ‘daterangepicker’ using following commands:
npm install daterangepicker
npm install @types/daterangepicker
and then tried to import it and use like that:
import { DateRangePicker } from 'daterangepicker';
const picker = new DateRangePicker('#date-picker', {
startDate: '01/01/2022',
endDate: '01/31/2022'
});
but it gives me the following error:
'DateRangePicker' only reffers to a type, but is being used as a value here
in their documentation they are using jQuery to call it but I wonder if I can import it and use in .ts file somehow? http://www.daterangepicker.com/
2
Answers
Try using
By using require instead of import, we can access the default export of the daterangepicker module as a value that can be instantiated with new.
This is an old javascript module that isn’t configured / setup for ES module import.
You can use this syntax to import and use it:
Or you can do as suggested in the comments and use require by importing
@types/node
and then:Or you can set
"esModuleInterop": true
in yourtsconfig
and then:https://www.typescriptlang.org/docs/handbook/modules.html