From 984f3613c5ad4a1acca3a3ffd84a430bcbc525e1 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 18 Apr 2022 05:26:23 -0700 Subject: [PATCH] fix: fix the error caused by using bundled time-delta in node env --- README.md | 5 +++-- lib/time-delta.js | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a750530..cbfadec 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Formats difference between two dates as a human-readable string in almost any la ### Node.js -In Node.js environment library will load requested locales automatically. +In Node.js environment library will load requested locales automatically from a relative path. ```js const timeDelta = require('time-delta'); @@ -76,7 +76,8 @@ timeDelta.addLocale([enLocale, ruLocale]); // Creating an instance const instance = timeDelta.create({ - locale: 'en', // default + locale: 'en', + autoloadLocales: false }); const date1 = new Date('2015-04-01T21:00:00'); diff --git a/lib/time-delta.js b/lib/time-delta.js index becaf41..05b9b7f 100644 --- a/lib/time-delta.js +++ b/lib/time-delta.js @@ -211,7 +211,9 @@ function requireLocale(localeId) { ); } catch (error) { - throw Error(`Failed to load locale: ${localeId}`); + throw Error( + `Failed to load locale: ${localeId} from ../locales/${localeId}.js. If using a bundled time-delta, set 'autoloadLocales: false' in the config.` + ); } }