Started working in Node two days back, and i have a unusual requirement. I have to reuse(maybe with minor unavoidable tweaks) a code that works in a browser and make it a rest API with Node. I have managed to remove all DOM interactions from the back-end code. Now i need to add jQuery
and jquery-datepicker
as the code uses datepicker.parseDate
and datepicker.formatDate
.
Below is the code i have so far
//index.js
// Load jsdom, and create a window.
var jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html>`);
window = dom.window;
// Load jQuery with the simulated jsdom window.
$ = jQuery = require('jquery')(window);
require('jquery-datepicker');
So i managed to create the window object using jsdom and initialized jquery by passing this window object. Now when i do require('date-picker')
, i get the following error inside date-picker node_modules file
\node_modules\jquery-datepicker\jquery-datepicker.js:55
$.fn.extend({
^
TypeError: Cannot read property 'extend' of undefined
so basically $.fn is undefined.
Any help?
via aneeshere
No comments:
Post a Comment