Skip to content

Using adapter for date formatting (date-fns, moment or luxon) without require - ESM? #144

@exetico

Description

@exetico

Describe the bug
I'm unable to use ChatjsNodeCanvas with a Chart.js adapter like date-fns. I've tried with date-fns, moment and luxon with no luck.

I've tried to search through the issues, but all workaround are with require usage.

Have I just missed something, or can't I use this with a adapter, if I'm unable to use require? (ES Module)

I'd really like to use a date adapter, as I'm normally during in front-end Chart.js :-).

Or is rendering through NodeJS just a thing I can do nativly in Chartjs 4, or? I've not found anything useful by searching around the topic, but maybe I've missed some important facts, or search keywords.

Versions

  • NodeJS version: v18.18.1
  • ChartjsNodeCanvas version: 4.1.6
  • Chart.JS version: 3.7.1 (Not 3.5.1, as we're using chartjs-plugin-annotation which has known bugs prior to 3.7, but I've tested with 3.5.1 too)
  • Typescript version (if applicable): Normal JavaScript

Additional context

I'm facing the classic Error [ERR_REQUIRE_ESM]: require() of ES Module, and I'm trying to get ChartjsNodeCanvas to work with a date adapter, but I've not found a way to do so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions