dvandal / cryptonote-nodejs-pool

Mining pool for all CryptoNote based coins using Cryptonight, Cryptonight Light and Cryptonight Heavy algorithms
GNU General Public License v2.0
367 stars 612 forks source link

TypeError: dateFormat is not a function #745

Open cryptomaxsun opened 1 week ago

cryptomaxsun commented 1 week ago

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?

ledlamp commented 1 week ago

make toISOString defined

ledlamp commented 1 week ago

you have to convert your code to es module to import es modules. otherwise you have to asynchronously use the module after it is loaded.

import("dateformat").then(({default: dateFormat}) => {
    // use dateFormat here
});
cryptomaxsun commented 1 week ago
node init.js
/home/max/pool/lib/exceptionWriter.js:22
                let time = dateFormat(toISOString defined(), 'yyyy-mm-dd HH:MM:ss');
                                      ^^^^^^^^^^^

SyntaxError: missing ) after argument list

exceptionWriter.js:22

/**
 * Cryptonote Node.JS Pool
 * https://github.com/dvandal/cryptonote-nodejs-pool
 *
 * Exception writer
 **/

// Load required modules
let fs = require('fs');
let cluster = require('cluster');
let dateFormat;
import("dateformat").then(({default: dateFormat}) => {
    // use dateFormat here
});

/**
 * Handle exceptions
 **/
module.exports = function (logSystem) {
    process.on('uncaughtException', function (err) {
        console.log('\n' + err.stack + '\n');
        let time = dateFormat(toISOString defined(), 'yyyy-mm-dd HH:MM:ss');
        fs.appendFile(config.logging.files.directory + '/' + logSystem + '_crash.log', time + '\n' + err.stack + '\n\n', function (err) {
            if (cluster.isWorker)
                process.exit();
        });
    });
};

What's wrong now?

ledlamp commented 1 week ago

🗿

ledlamp commented 1 week ago

Well it looks like you are trying to run someone else's module so you shouldn't have to be modifying the code. It looks like you have wrong version of dateformat module.

2024-11-14_23-36-51 311_dvandalcryptonote-nodejs-pool_Mining_pool_for_all_

This is wrong. Do not use npm update. Use npm install. Then it will install dateformat 4.5.1 as specified in package.json and it should work. Otherwise it installs latest version which is not compatible.

cryptomaxsun commented 1 week ago

151124

ledlamp commented 1 week ago

no clone the repo again and start over

cryptomaxsun commented 4 days ago

2311242

I did as you said, now this problem.

http://sal.ms-pool.net.ua

2311243

Why are statistics not displayed when the pool is running?

cryptomaxsun commented 1 day ago

261124 Help me, please!

domajor commented 1 day ago

Did you find a solution?

cryptomaxsun commented 1 day ago

Did you find a solution?

No