cryptonote-nodejs-pool icon indicating copy to clipboard operation
cryptonote-nodejs-pool copied to clipboard

TypeError: dateFormat is not a function

Open cryptomaxsun opened this issue 1 year ago • 11 comments

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?

cryptomaxsun avatar Nov 14 '24 13:11 cryptomaxsun

make toISOString defined

ledlamp avatar Nov 14 '24 22:11 ledlamp

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
});

ledlamp avatar Nov 14 '24 23:11 ledlamp

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?

cryptomaxsun avatar Nov 15 '24 06:11 cryptomaxsun

🗿

ledlamp avatar Nov 15 '24 07:11 ledlamp

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.

ledlamp avatar Nov 15 '24 07:11 ledlamp

151124

cryptomaxsun avatar Nov 15 '24 10:11 cryptomaxsun

no clone the repo again and start over

ledlamp avatar Nov 15 '24 19:11 ledlamp

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 avatar Nov 23 '24 09:11 cryptomaxsun

261124 Help me, please!

cryptomaxsun avatar Nov 26 '24 16:11 cryptomaxsun

Did you find a solution?

domajor avatar Nov 26 '24 19:11 domajor

Did you find a solution?

No

cryptomaxsun avatar Nov 26 '24 19:11 cryptomaxsun