Open DanielRuf opened 2 months ago
No ESM support in pkg yet:
Checking how to resolve that.
Got it working, as CommonJS compiled with rollup and as static binary with pkg:
npm run build
pkg .
node cli.cjs --enableServer 1
./highcharts-export-server-linux --enableServer 1
Minimal changes that I did:
Minimal testing via --enableServer 1
was successful. I think it makes sense to either publish binaries directly (we do not want to install and run NodeJS on the server) or at least document the way to create a binary with pkg.
Also I think there should be some of my changes in the highcharts-export-server code, as they may make the code more portable.
The patch / diff can be applied like this (alternatively use patch-package or yarn / pnpm):
wget https://registry.npmjs.org/highcharts-export-server/-/highcharts-export-server-3.1.1.tgz
tar xzf highcharts-export-server-3.1.1.tgz
patch --directory=package/ --strip=1 < patch.diff
The following code should probably not be used then, because it fills the tmp folder with every execution.
const RANDOM_PID = node_crypto.randomBytes(64).toString('base64url');
const PUPPETEER_DIR = path.join('tmp', `puppeteer-${RANDOM_PID}`);
I guess this needs some further improvement.
Looks like in v4 there is not this logic with the mentioned code anymore: https://github.com/highcharts/node-export-server/blob/e86e39c52b65d4ffe940ec56e47b438091b0bb0f/lib/browser.js
Regarding statically compiled binaries (can be added to GitHub releases), these would make usage without NodeJS on servers much easier.
@cvasseng can this logic be removed again and a new v3 patch release done?
@DanielRuf I've analyzed this issue now and in v4.0.0 we got rid of this part of problematic logic that you've mentioned (as you've correctly pointed out). Thus, this is no longer a problem on the current master branch (which contains the v4.0.0 that is about to be published on npm).
The v4.0.0 includes drastic performance improvements and multiple bug fixes. It has officially been deployed as the Highcharts Export Server (https://export.highcharts.com/) with a success rate of over 99%.
I recommend you try it out. We will release it on npm soon, once we fully update the changelog.
Regarding the second part of your question which is the prebuilt binary, I have added it to our backlog so that we can discuss it in the future. After all the prioritized issues are solved (bugs & performance always have the highest priority), we may include this in one of the upcoming releases so I'm leaving this issue open.
I would like to use the CLI of v4 as statically compiled binary.
Because this way we can get rid of NodeJS as separate dependency on servers in production.
Currently our setup looks like that (on Windows): PHP => bat file => node export.js => highcharts-export-server
My goal is this:
PHP => highcharts-export-server CLI (statically compiled)
I will try to adjust the patch for v4 and clean it up, so that I can get rid of the overly complex solution (which leads to multiple issues because of that).
My second best solution currently is to use npx, which would be PHP => npx => highcharts-export-server CLI.
Install pkg:
Compile CLI with NodeJS 20:
Log
``` pkg . -t node20-linux-x64,node20-macos-x64,node20-win-x64 > pkg@5.12.0 > Fetching base Node.js binaries to PKG_CACHE_PATH fetched-v20.11.1-linux-x64 [====================] 100% fetched-v20.11.1-macos-x64 [====================] 100% fetched-v20.11.1-win-x64 [====================] 100% > Warning Cannot include directory %1 into executable. The directory must be distributed with executable as %2. %1: ../puppeteer/.local-chromium %2: path-to-executable/puppeteer > Warning Cannot include directory %1 into executable. The directory must be distributed with executable as %2. %1: ../puppeteer/.local-chromium %2: path-to-executable/puppeteer > Warning Babel parse has failed: import.meta may appear only with 'sourceType: "module"' (24:55) > Warning Babel parse has failed: import.meta may appear only with 'sourceType: "module"' (70:49) > Warning Babel parse has failed: import.meta may appear only with 'sourceType: "module"' (27:49) > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/bin/cli.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/index.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/config.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/utils.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/server.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/chart.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/logger.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/pool.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/cache.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/schemas/config.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/rate_limit.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/health.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/export.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/change_hc_version.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/ui.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/browser.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/export.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/fetch.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/bin/cli.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/index.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/config.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/utils.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/server.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/chart.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/logger.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/pool.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/cache.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/schemas/config.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/rate_limit.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/health.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/export.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/change_hc_version.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/server/routes/ui.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/browser.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/export.js > Warning Failed to make bytecode node20-x64 for file /snapshot/node_modules/highcharts-export-server/lib/fetch.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\bin\cli.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\index.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\config.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\utils.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\server\server.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\chart.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\logger.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\pool.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\cache.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\schemas\config.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\server\rate_limit.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\server\routes\health.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\server\routes\export.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\server\routes\change_hc_version.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\server\routes\ui.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\browser.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\export.js > Warning Failed to make bytecode node20-x64 for file C:\snapshot\node_modules\highcharts-export-server\lib\fetch.js ```Run compiled CLI:
So currently there are a few problems, which should be resolved to make the CLI compilable.