In a CentOS 8 with nodejs v18.15.0 and npm v.9.5.0 when running jhispter version 7.9.3 I get the error:

[user@machine egeria-portal]$ jhipster
INFO! Using bundled JHipster
node:internal/modules/cjs/loader:571
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/util/namespace' is not defined by "exports" in /usr/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:697:9)
    at resolveExports (node:internal/modules/cjs/loader:565:36)
    at Module._findPath (node:internal/modules/cjs/loader:634:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/usr/lib/node_modules/generator-jhipster/utils/blueprint.js:19:25) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v18.15.0
[user@machine egeria-portal]

This error seems to occur in jhipster on certain nodejs 18 versions, and not on earlier ones like nodejs 16.


To solve it, you must add the following to the file /usr/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/package.json within "exports":

"./lib/util/namespace": "./lib/util/namespace.js"

staying like for example:

[user@machine workbench]$ cat /usr/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/package.json
{
  "name": "yeoman-environment",
  "version": "3.10.0",
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
  "homepage": "http://yeoman.io",
  "author": "Yeoman",
  "bin": {
    "yoe": "cli/index.js"
  },
  "files": [
    "cli",
    "lib"
  ],
  "main": "lib/environment.js",
  "exports": {
    "./lib/util/namespace": "./lib/util/namespace.js",
    ".": "./lib/environment.js",
    "./cli/": "./cli/",
    "./lib/": "./lib/",
    "./lib/util/": "./lib/util/",
    "./adapter": "./lib/adapter.js",
    "./conflicter": "./lib/util/conflicter.js",
    "./log": "./lib/util/log.js",
    "./transform": "./lib/util/transform.js",
    "./package.json": "./package.json"
  },
  "keywords": [
    "development",
...
...
    ],
    "rules": {
      "import/no-dynamic-require": "off",
      "import/extensions": "off",
      "prefer-spread": "off",
      "padding-line-between-statements": "off",
      "unicorn/no-hex-escape": "off",
      "unicorn/prefer-reflect-apply": "off",
      "prefer-rest-params": "off",
      "node/prefer-promises/fs": "off",
      "promise/prefer-await-to-then": "off",
      "unicorn/no-array-reduce": "off",
      "unicorn/import-style": "off"
    }
  }
}
[user@machine workbench]$ 


And with this it works:

[user@machine myapp]$ jhipster
INFO! Using bundled JHipster

        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝
                            https://www.jhipster.tech
Welcome to JHipster v7.9.3

Application files will be generated in folder: /home/user/workspaces/feitam/myapp/code/app/myapp-portal
 _______________________________________________________________________________________________________________

  Documentation for creating an application is at https://www.jhipster.tech/creating-an-app/
  If you find JHipster useful, consider sponsoring the project at https://opencollective.com/generator-jhipster
 _______________________________________________________________________________________________________________

? May JHipster anonymously report usage statistics to improve the tool over time? (Y/n)