How to fix ReferenceError: primordials is not defined in node

I hit the same error. I suspect you're using node 12 and gulp 3. That combination does not work: https://github.com/gulpjs/gulp/issues/2324

A previous workaround from Jan. does not work either: https://github.com/gulpjs/gulp/issues/2246

Solution: Either upgrade to gulp 4 or downgrade to an earlier node.


We encountered the same issue when updating a legacy project depending on [email protected] to Node.js 12+.

These fixes enable you to use Node.js 12+ with [email protected] by overriding graceful-fs to version ^4.2.4.

If you are using yarn v1

Yarn v1 supports resolving a package to a defined version. You need to add a resolutions section to your package.json:

{
  // Your current package.json contents
  "resolutions": {
    "graceful-fs": "^4.2.4"
  }
}

Thanks @jazd for this way to solve the issue.

If you are using npm

Using npm-force-resolutions as a preinstall script, you can obtain a similar result as with yarn v1. You need to modify your package.json this way:

{
  // Your current package.json
  "scripts": {
    // Your current package.json scripts
    "preinstall": "npx npm-force-resolutions"
  },
  "resolutions": {
    "graceful-fs": "^4.2.4"
  }
}

npm-force-resolutions will alter the package-lock.json file to set graceful-fsto the wanted version before the install is done.

If you are using a custom .npmrc file in your project and it contains either a proxy or custom registry, you might need to change npx npm-force-resolutions to npx --userconfig .npmrc npm-force-resolutions because as of now, npx doesn't use the current folder .npmrc file by default.

Origin of the problem

This issue stems from the fact that [email protected] depends on graceful-fs@^3.0.0 which monkeypatches Node.js fs module.

This used to work with Node.js until version 11.15 (which is a version from a development branch and shouldn't be used in production).

graceful-fs@^4.0.0 does not monkeypatch Node.js fs module anymore, which makes it compatible with Node.js > 11.15 (tested and working with versions 12 and 14).

Note that this is not a perennial solution but it helps when you don't have the time to update to gulp@^4.0.0.


Fix it in 1 minute:

Just follow these steps. I'm on windows 10 and it worked perfectly for me!

  1. In the same directory where you have package.json create a npm-shrinkwrap.json file with the following contents:
    {
      "dependencies": {
        "graceful-fs": {
            "version": "4.2.2"
         }
      }
    }
  1. Run npm install, and don't worry, it will update npm-shrinkwrap.json with a bunch of content.

  2. Run gulp to start the project.