Error with primordials not defined when running Node.js with Gulp and Angular CLI

I’m running Node.js version v22.12.0 and Gulp version CLI version: 3.0.0 and Local version: 5.0.0. When I try to run my project with Angular CLI, I encounter the following error:

fs.js:44
} = primordials;
    ^

ReferenceError: primordials is not defined
    at fs.js:44:5
    at req_ (C:UsersMyBook Hype AMDAppDataRoamingnpmnode_modulesangular-clinode_modulesnativesindex.js:143:24)
    at Object.req [as require] (C:UsersMyBook Hype AMDAppDataRoamingnpmnode_modulesangular-clinode_modulesnativesindex.js:55:10)
    at Object.<anonymous> (C:UsersMyBook Hype AMDAppDataRoamingnpmnode_modulesangular-clinode_modulesyamnode_modulesgraceful-fsfs.js:1:37)
    at Module._compile (node:internal/modules/cjs/loader:1565:14)
    at Object..js (node:internal/modules/cjs/loader:1708: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:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)

Node.js v22.12.0

Project Setup:

  • Node version: v22.12.0
  • Gulp CLI version: 3.0.0
  • Gulp local version: 5.0.0
  • Angular CLI version: 14.2.13

Gulp task runner is included in the project.

My package.json looks like this:

{
  "name": "deer-dialect-web",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.2.0",
    "@angular/common": "^14.2.0",
    "@angular/compiler": "^14.2.0",
    "@angular/core": "^14.2.0",
    "@angular/forms": "^14.2.0",
    "@angular/localize": "^14.3.0",
    "@angular/material": "^14.2.7",
    "@angular/material-moment-adapter": "^14.2.7",
    "@angular/platform-browser": "^14.2.0",
    "@angular/platform-browser-dynamic": "^14.2.0",
    "@angular/router": "^14.2.0",
    "@angular/youtube-player": "^13.3.9",
    "@ng-bootstrap/ng-bootstrap": "^13.1.1",
    "@ngx-translate/core": "^14.0.0",
    "@ngx-translate/http-loader": "^7.0.0",
    "bootstrap": "^5.3.3",
    "bootstrap-icons": "^1.10.0",
    "ngx-toastr": "^14.3.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.13",
    "@angular/cli": "~14.2.13",
    "@angular/compiler-cli": "^14.2.0",
    "@types/jasmine": "~4.0.0",
    "gulp": "^5.0.0",
    "jasmine-core": "~4.3.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.7.2"
  }
}

{
  "name": "deer-dialect-web",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.2.0",
    "@angular/common": "^14.2.0",
    "@angular/compiler": "^14.2.0",
    "@angular/core": "^14.2.0",
    "@angular/forms": "^14.2.0",
    "@angular/localize": "^14.3.0",
    "@angular/material": "^14.2.7",
    "@angular/material-moment-adapter": "^14.2.7",
    "@angular/platform-browser": "^14.2.0",
    "@angular/platform-browser-dynamic": "^14.2.0",
    "@angular/router": "^14.2.0",
    "@angular/youtube-player": "^13.3.9",
    "@ng-bootstrap/ng-bootstrap": "^13.1.1",
    "@ngx-translate/core": "^14.0.0",
    "@ngx-translate/http-loader": "^7.0.0",
    "bootstrap": "^5.3.3",
    "bootstrap-icons": "^1.10.0",
    "ngx-toastr": "^14.3.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.13",
    "@angular/cli": "~14.2.13",
    "@angular/compiler-cli": "^14.2.0",
    "@types/jasmine": "~4.0.0",
    "gulp": "^5.0.0",
    "jasmine-core": "~4.3.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.7.2"
  }
}

Steps I’ve Tried:

  • I have tried updating the dependencies and reinstalling them (npm
    install).
  • I have also tried downgrading the gulp version to 4.x but the error
    still persists.
  • I ensured that my Node.js version is compatible with the
    dependencies in the project.

Additional Information:

  • The error seems to be related to the primordials variable, which is
    not defined. It might be related to the graceful-fs package, which is
    used by angular-cli and gulp.
  • I am using Node.js v22.12.0, which could be a potential compatibility
    issue with older versions of the gulp or angular-cli tools.

Question:

How can I resolve the primordials is not defined error, especially considering my Node.js version? Do I need to downgrade my Node.js version or is there another fix?