Running node JS file directly is successful but through cron - failure - Error [ERR_REQUIRE_ESM]
When I run a .js file directly, it is successful, but through cron it fails with an error about a package that I didn't even know was installed. Why are the results different?
adrian@nfp:~$ node upd_ATC_ALC_daily_from_server_file.js <-- successful
00 01 * * * node /home/adrian/nfp-repo/login/upd_ATC_ALC_daily_from_server_file.js >> /tmp/crlog.log 2>&1 | logger -t mycmd
adrian@nfp:/tmp$ cat crlog.log
Mon Mar 9 01:14:01 UTC 2026 Hello from crontab
/home/adrian/nfp-repo/login/node_modules/html-encoding-sniffer/lib/html-encoding-sniffer.js:2
const { getBOMEncoding, labelToName } = require("@exodus/bytes/encoding-lite.js");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/adrian/nfp-repo/login/node_modules/@exodus/bytes/encoding-lite.js from /home/adrian/nfp-repo/login/node_modules/html-encoding-sniffer/lib/html-encoding-sniffer.js not supported.
Instead change the require of encoding-lite.js in /home/adrian/nfp-repo/login/node_modules/html-encoding-sniffer/lib/html-encoding-sniffer.js to a dynamic import() which is available in all CommonJS modules.
at Object. (/home/adrian/nfp-repo/login/node_modules/html-encoding-sniffer/lib/html-encoding-sniffer.js:2:41) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v20.11.0