codebox / moment-precise-range

A moment.js plugin to display human-readable date/time ranges
https://codebox.net/pages/moment-date-range-plugin
MIT License
150 stars 91 forks source link

require function is used in a way in which dependencies cannot be statically extracted #22

Closed sandeshds closed 7 years ago

sandeshds commented 7 years ago

Getting this error while importing "moment-precise-range-plugin". I believe it is caused due to the following statement

if (typeof moment === "undefined" && require) { moment = require('moment'); }

changing it to if (typeof moment === "undefined") { moment = require('moment'); }

fixes the issue. Is there a workaround or fix to this ?

andfaulkner commented 7 years ago

The issue is coming from the very first lines of the module (moment-precise-range.js):

if (typeof moment === "undefined" && require) {

The error goes away if we replace it with:

if (typeof moment === "undefined" && typeof require === 'function') {

I tried this out locally, and it works perfectly. It also retains the intended purpose of checking for require's existence: to ensure it can be called.

I've created a PR for it: #23

codebox commented 7 years ago

fixed by @andfaulkner

sandeshds commented 7 years ago

I have been using it as an npm package and using the version '1.2.1'. I see that there is no new version that has been published. Are we planning to publish the new version with the fix ?

codebox commented 7 years ago

npm now at version 1.2.4 which includes latest fixes