node-export-server icon indicating copy to clipboard operation
node-export-server copied to clipboard

ReferenceError: moment is not defined

Open Pascal76 opened this issue 10 months ago • 3 comments

Hello,

I try to use node-export-server from docker with a formatter using moment.js :

datethe = moment().year(datetheYW[0]).isoWeek(datetheYW[1]).startOf('isoWeek').format('YYYY-MM-DD') + '  w' + datetheYW[1] + '';

but I got this error : ReferenceError: moment is not defined

/bin/docker run -u 0:0 --rm --tmpfs=/run highcharts_es cat lib/schemas/config.js contains : custom: [ 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.45/moment-timezone-with-data.min.js' ]

On the dockerfile : ENV HIGHCHARTS_MOMENT="YES" (or true or 1) I am not sure it is still valid because HIGHCHARTS_MOMENT does not appear on the documentation + npm install -S moment moment-timezone luxon (...) I am not sure it is needed given lib/schemas/config.js

Could you help me to understand how to make it work please ?

The command line: /usr/local/bin/highcharts-export-server --resources '[]' --allowFileResources true --allowCodeExecution true --infile "$from" --outfile "$to" $width $height $scale --logLevel 2 --nologo true 2>&1

Pascal76 avatar Mar 19 '25 20:03 Pascal76

The solution I found, but I don't think it is the best (I would prefer it gets the local file)

On the Dockerfile I added : ADD ["template.html","templates"]

And on template.html I added :

Pascal76 avatar Mar 25 '25 16:03 Pascal76

Hi @Pascal76,

The HIGHCHARTS_MOMENT is not a valid option or environment variable to set. The moment scripts are expected to be loaded by default, just like any other Highcharts script defined in the ./schemas/config.js file. Could you share your Docker configuration?

PaulDalek avatar Jun 02 '25 13:06 PaulDalek

FROM node:22

WORKDIR /

ADD ["fonts","/usr/share/fonts"]

USER root

RUN addgroup --gid 48 apache RUN adduser --disabled-password --gecos '' --uid 48 --gid 48 apache

RUN git clone https://github.com/highcharts/node-export-server.git

WORKDIR /node-export-server

ADD ["AST.allowedAttributes.js","/node-export-server"]

RUN chown -R node /node-export-server &&
echo '[]' > resources.json &&
chmod 644 AST.allowedAttributes.js resources.json

USER node

ENV TZ="Europe/Paris" ENV HIGHCHARTS_CDN_URL="https://cdnjs.cloudflare.com/ajax/libs/highcharts/" ENV ACCEPT_HIGHCHARTS_LICENSE="YES" ENV HIGHCHARTS_VERSION=12.2.0 ENV OTHER_NO_LOGO=true ENV HIGHCHARTS_USE_STYLED="YES" ENV HIGHCHARTS_USE_MAPS="NO" ENV HIGHCHARTS_MOMENT=true ENV HIGHCHARTS_USE_GANTT="NO" ENV OPENSSL_CONF=/dev/null

RUN rm package-lock.json &&
npm install -S moment moment-timezone luxon &&
npm install &&
mkdir log .cache tmp &&
chmod 777 .cache log

USER root RUN npm link --unsafe-perm RUN apt update && apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libnss3 lsb-release xdg-utils wget ca-certificates

USER node

WORKDIR /node-export-server

ADD ["config.json","/node-export-server"] ADD ["template.html","templates"]

Pascal76 avatar Jun 02 '25 16:06 Pascal76