HackMyResume icon indicating copy to clipboard operation
HackMyResume copied to clipboard

i get the error while running the command like this

Open Winningshankar1985 opened this issue 2 years ago • 1 comments

hi guys, i get an error like this while running the command in my backend. Command failed: hackmyresume build ./resume-sample/res.json TO ./resume-sample/resume-modern.html -t node_modules/jsonresume-theme-modern -o html /home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/node_modules/chalk/index.js:2 const escapeStringRegexp = require('escape-string-regexp'); ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/escape-string-regexp/index.js from /home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/node_modules/chalk/index.js not supported. Instead change the require of /home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/escape-string-regexp/index.js in /home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/node_modules/chalk/index.js to a dynamic import() which is available in all CommonJS modules. at Object. (/home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/node_modules/chalk/index.js:2:28) at Object. (/home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/dist/utils/md2chalk.js:11:11) at Object. (/home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/dist/utils/md2chalk.js:26:4) at Object. (/home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/dist/cli/error.js:17:9) at Object. (/home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/dist/cli/error.js:285:4) at Object. (/home/kuber/.nvm/versions/node/v16.20.2/lib/node_modules/hackmyresume/dist/cli/index.js:20:3) { code: 'ERR_REQUIRE_ESM' } here is my package.json { "name": "backend", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "child_process": "^1.0.2", "cors": "^2.8.5", "ejs": "^3.1.9", "escape-string-regexp": "^5.0.0", "express": "^4.18.2", "fs": "^0.0.1-security", "hackmyresume": "^1.9.0-beta", "handlebars": "^4.7.8", "html-docx-js": "^0.3.1", "html-to-image": "^1.11.11", "jsonresume-theme-elegant": "^1.3.10", "jsonresume-theme-modern": "^0.0.5", "path": "^0.12.7", "pump": "^3.0.0", "puppeteer": "^21.3.4", "resume": "^0.0.1", "resume-cli": "^3.0.0", "util": "^0.12.5" } } and my code :

const hackmyresume = require('hackmyresume'); const eleganttheme = require('jsonresume-theme-elegant'); const moderntheme = require('jsonresume-theme-modern'); const fs = require('fs').promises; const { exec } = require('child_process'); const { promisify } = require('util');

const execPromise = promisify(exec); async function generateResume(resumeFile, theme, format) { const resumeString = JSON.stringify(resumeFile);

await fs.writeFile(__dirname+'/resume-sample/res.json', resumeString);

// Create a temporary file name for the output const tmpFile = ${__dirname}/resume-sample/resume-${theme}.${format};

// Create a new hackmyresume process const themes={ 'modern': moderntheme, 'elegant': eleganttheme, };

const command = hackmyresume build ./resume-sample/res.json TO ./resume-sample/resume-${theme}.html -t node_modules/jsonresume-theme-${theme} -o html; // Try to execute the command and catch any errors try { await execPromise(command); } catch (error) { console.error('Error executing hackmyresume command:', error); throw error; }

// Try to read the output file as a buffer and catch any errors try { const output = await fs.readFile(tmpFile); return output; // Return the output as a buffer } catch (error) { console.error('Error reading the output file:', error); throw error; }

}

// Example usage:

module.exports = { generateResume, };

Can anyone point out what i'm doing wrong here.

Winningshankar1985 avatar Oct 02 '23 13:10 Winningshankar1985