Fixing the error “ReferenceError: primordials is not defined” in Gulp

If you’ve come across this:

ReferenceError: primordials is not defined

while trying to run an old Gulp project, you’re not alone. It’s a frustrating issue caused by version mismatches between Node.js and the dependencies in your project, particularly Gulp and some underlying modules.

I’ve run into this a few times when revisiting legacy projects or helping agencies update older codebases. The fix isn’t too difficult once you know what’s going on, but the error messages aren’t exactly beginner-friendly.

Here’s how I troubleshoot and fix the issue so you can get back to actually building things.

Remove Dependencies:

Delete the node_modules folder.

2. Create npm-shrinkwrap.json

Create a file named npm-shrinkwrap.json in your project directory with content specifying version 4.2.2 of graceful-fs.

{
    "dependencies": {
        "graceful-fs": {
            "version": "4.2.2"
        }
    }
}

Install Dependencies Again

Run npm install to install the dependencies with the updated versions.

And voila! Your project should now run! This workaround is only if you want to avoid upgrading to Gulp v4 and need to get a Gulp v3 project up and running.

Don’t forget to add npm-shrinkwrap.json to gitignore!

Once you’ve run npm install again, your npm-shrinkwrap.json file will now be updated with the content it needs to get the project running. This will only work on your own machine, so it’s best to add npm-shrinkwrap.json to your gitignore, other team members will need to run their own npm-shrinkwrap.json file.

Need more help?

I work with lots of legacy front-end setups and can help modernise, streamline, or simply debug what’s already there.

If you’re stuck on a stubborn dev issue (or need help upgrading your tools), drop me a message – I’d be happy to take a look.


Leave a Reply

Your email address will not be published. Required fields are marked *

Let's talk

Whether it’s a small step or a giant leap, I’m here to guide your project.

Make contact