Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: dateFormat is not a function #745

Open
cryptomaxsun opened this issue Nov 14, 2024 · 11 comments
Open

TypeError: dateFormat is not a function #745

cryptomaxsun opened this issue Nov 14, 2024 · 11 comments

Comments

@cryptomaxsun
Copy link
Contributor

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
Copy link

ledlamp commented Nov 14, 2024

make toISOString defined

@ledlamp
Copy link

ledlamp commented Nov 14, 2024

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
Copy link
Contributor Author

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
Copy link

ledlamp commented Nov 15, 2024

🗿

@ledlamp
Copy link

ledlamp commented Nov 15, 2024

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
Copy link
Contributor Author

151124

@ledlamp
Copy link

ledlamp commented Nov 15, 2024 via email

@cryptomaxsun
Copy link
Contributor Author

cryptomaxsun commented Nov 23, 2024

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
Copy link
Contributor Author

261124
Help me, please!

@domajor
Copy link

domajor commented Nov 26, 2024

Did you find a solution?

@cryptomaxsun
Copy link
Contributor Author

Did you find a solution?

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants