Node throws error on 'hackmyresume new'

Author: leoossaCreated Jul 21, 2021Updated Nov 1, 2024

At first hackmyresume new threw:

node:internal/modules/cjs/loader:944
  throw err;
  ^

Error: Cannot find module 'escape-string-regexp'
Require stack:
- /usr/lib/node_modules/hackmyresume/node_modules/chalk/index.js
- /usr/lib/node_modules/hackmyresume/dist/utils/md2chalk.js
- /usr/lib/node_modules/hackmyresume/dist/cli/error.js
- /usr/lib/node_modules/hackmyresume/dist/cli/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/usr/lib/node_modules/hackmyresume/node_modules/chalk/index.js:2:28)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Module.require (node:internal/modules/cjs/loader:1013:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/lib/node_modules/hackmyresume/node_modules/chalk/index.js',
    '/usr/lib/node_modules/hackmyresume/dist/utils/md2chalk.js',
    '/usr/lib/node_modules/hackmyresume/dist/cli/error.js',
    '/usr/lib/node_modules/hackmyresume/dist/cli/index.js'
  ]
}

It was installed with sudo npm install hackmyresume -g.

I tried solutions:

  • npm install --save escape-string-regexp; delete your item/node_module and then re-execute npm install
  • npm install --save-dev escape-string-regexp
  • npm i -g npm; delete the node_modules folder and run npm cache clean and then npm install

suggested here and here but none of them helped.

Eventually I installed package globally with sudo npm install --save-dev escape-string-regexp -g that helped with finding the package and resolving previous issue, but effectively coming with the new one:

node:internal/modules/cjs/loader:1126
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/lib/node_modules/escape-string-regexp/index.js
require() of ES modules is not supported.
require() of /usr/lib/node_modules/escape-string-regexp/index.js from /usr/lib/node_modules/hackmyresume/node_modules/chalk/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /usr/lib/node_modules/escape-string-regexp/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/lib/node_modules/escape-string-regexp/package.json.

    at new NodeError (node:internal/errors:363:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1126:13)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/usr/lib/node_modules/hackmyresume/node_modules/chalk/index.js:2:28)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32) {
  code: 'ERR_REQUIRE_ESM'
}

I'm not proud to admit that resigned of further investigation because I installed fork of hackmyresume that is FluentCV and it works out-of-the-box. I'm opening this issue because it may be useful for somebody one day and that info may help if any comes up with similar problem.