question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sudden space export error: "date-fns doesn't accept strings as date arguments"

See original GitHub issue

Hi, I’m suddenly getting errors when running the contentful export space. It happened after updating the NPM package to the latest version contentful-cli@1.14.2.

I experienced it first suddenly in a pipeline (which also used the latest version). In my search for replicating it locally, I updated my local version to the latest one. But now, even when downgrading, the issue strangely remains.

Expected Behavior

Usual export to file, without errors.

Actual Behavior

Error in the CLI output (and also a exported file…)

The following 8 errors and 8 warnings occurred:

Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule
Error
    at toDate (/Users/x/.nvm/versions/node/v12.0.0/lib/node_modules/contentful-cli/node_modules/date-fns/toDate/index.js:56:20)
    at format (/Users/x/.nvm/versions/node/v12.0.0/lib/node_modules/contentful-cli/node_modules/date-fns/format/index.js:389:42)
    at /Users/x/.nvm/versions/node/v12.0.0/lib/node_modules/contentful-cli/node_modules/contentful-batch-libs/dist/logging.js:138:55
    at Array.map (<anonymous>)
    at displayErrorLog (/Users/x/.nvm/versions/node/v12.0.0/lib/node_modules/contentful-cli/node_modules/contentful-batch-libs/dist/logging.js:138:14)
    at /Users/x/.nvm/versions/node/v12.0.0/lib/node_modules/contentful-cli/node_modules/contentful-export/dist/index.js:186:46
    at async exportSpace (/Users/x/.nvm/versions/node/v12.0.0/lib/node_modules/contentful-cli/lib/cmds/space_cmds/export.js:181:24)
🚨  Error: Invalid time value

Steps to Reproduce

It at least happens on a export with content:

contentful space export --space-id <x> --environment-id <x> --skip-content false --download-assets true --export-dir <x> --management-token <x>

Context

I’m trying to export all content/content models (including assets) of an existing space, and want to import it in a new empty space.

Environment

Node Version: 12.0.0 Npm Version: 6.9.0 Operating System: Darwin MacBook-Pro.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64 Package Version: contentful-cli@1.14.2 (although after this installation even downgrading to 1.13.0 presents the error, perhaps some cache of a subpackage?)

Pipeline runs on Ubuntu (latest)

Update

It seems to be related to the change of moment to date-fns. Not sure if it’s specifically this release or a few earlier where moment was replaced with date-fns.

One of the changes: https://github.com/contentful/contentful-cli/commit/f3de91ed2b20d126be515ec871740b6502158780?diff=split

As it’s a sub-package, I’ve not yet been able to modify the package correctly…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
paulstrawcommented, Jun 7, 2022

I can confirm that the date-fns fix above, released in contentful-batch-libs 9.4.1, resolved the issue for us. Thanks @Brad-Turner!

3reactions
Brad-Turnercommented, Jun 4, 2022

Hey @bacpac, this issue was related to replacing moment with date-fns in the contentful-batch-libs repository. I have implemented a fix - just awaiting approval from the team at contentful. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Starting with v2.0.0-beta.1 date-fns doesn't accept strings as ...
So, until I deployed today I was using version ^2.0.0-alpha.7 with no issues, but then got the following error: Starting with v2.0.0-beta.1 ...
Read more >
date-fns doesn't accept strings as date arguments. Please use ...
new Date('2021-7-13T12:30:00.000Z') produces an invalid date, that's why you're start and end properties are set to null . The correct string ...
Read more >
@types/date-fns | Yarn - Package Manager
BREAKING: toDate (previously parse ) now doesn't accept string arguments but only numbers and dates. toDate called with an invalid argument will return...
Read more >
client/node_modules/date-fns/CHANGELOG.md - GitLab
BREAKING: toDate (previously parse ) now doesn't accept string arguments but only numbers and dates. toDate called with an invalid argument will return...
Read more >
Why you should use date-fns for manipulating dates with ...
In date-fns you only load the functions that you really need. This doesn't matter too much in a backend application with Node.js though,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found