Skip to content

TypeError: dateFormat is not a function #745

@cryptomaxsun

Description

@cryptomaxsun

I got an error when starting the pool

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/max/pool/node_modules/dateformat/lib/dateformat.js from /home/max/pool/lib/logger.js not supported.
Instead change the require of dateformat.js in /home/max/pool/lib/logger.js to a dynamic import() which is available in all CommonJS modules.

corrected in the file in logger.js

let dateFormat;
(async () => {
  dateFormat = (await import('dateformat')).default;
})();

Starting a pool

node init.js

TypeError: dateFormat is not a function
    at global.log (/home/max/pool/lib/logger.js:71:13)
    at Object.<anonymous> (/home/max/pool/init.js:24:2)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at node:internal/main/run_main_module:36:49

/home/max/pool/lib/exceptionWriter.js:22
                let time = dateFormat(toISOString(), 'yyyy-mm-dd hh:MM:ss');
                           ^

ReferenceError: toISOString is not defined
    at process.<anonymous> (/home/max/pool/lib/exceptionWriter.js:22:14)

How can this be fixed?

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