Gulp crashes at start with "primordials is not defined"
ReferenceError: primordials is not definedShort answer
This error means an old copy of graceful-fs, pulled in by Gulp 3, is running on a Node.js version it cannot work with. Gulp 4 does not ship that old copy. Upgrade to a current gulp, move gulp-sass to the sass package, and find any other dependency that still drags Gulp 3 into your lockfile.
Fix it fast
1Find out which cause you have
Find out which gulp and which graceful-fs your project really resolves. If gulp is 3.x or graceful-fs is 3.x, this page is your problem.
npm ls gulp graceful-fs2Match what you see, then jump to its fix
- 1
npm ls shows gulp@3.x, and the stack trace starts in fs.js with the primordials lineThe project still runs Gulp 3Fix - 2
The gulpfile does require('gulp-sass') followed by a call to sass, or the build also fails in node-sassgulp-sass is on an old release or still uses node-sassFix - 3
package.json says gulp 4, but npm ls still shows gulp@3 under some other packageAnother dependency pulls Gulp 3 into the lockfileFix
- 1
What does the error look like?
ReferenceError: primordials is not definedconst { Math, Object, Reflect } = primordials;
Cause 1 of 3
The project still runs Gulp 3
1Check
The gulp maintainers traced this error to the natives module, which comes from a very outdated graceful-fs. Gulp 3 depends on that old chain; Gulp 4 does not. Check the version in package.json.
node --version
npx gulp --version
grep '"gulp"' package.json2Fix
Install the gulp CLI globally and a current gulp locally, then rewrite the gulpfile for the gulp 4 task API: compose with gulp.series and gulp.parallel, and register tasks as plain functions.
npm rm --global gulp
npm install --global gulp-cli
npm install --save-dev gulp@latest3Verify
The CLI starts and prints a local gulp version of 4 or higher.
gulp --versionConfirmed by github.com
Cause 2 of 3
gulp-sass is on an old release or still uses node-sass
1Check
Current gulp-sass wants Gulp 4 and a Sass compiler that you pass in yourself. Node Sass is deprecated, and Dart Sass is the recommended compiler.
npm ls gulp-sass sass node-sass2Fix
Install sass next to gulp-sass and hand it to gulp-sass in the gulpfile. Remove node-sass.
npm uninstall node-sass
npm install --save-dev sass gulp-sass
// gulpfile.js
const sass = require('gulp-sass')(require('sass'));3Verify
Run your styles task. It should compile without the ReferenceError.
npx gulp stylesConfirmed by github.com
Cause 3 of 3
Another dependency pulls Gulp 3 into the lockfile
1Check
A gulp maintainer says that on Gulp 4 the cause would be a different issue within your project, such as an incorrect lockfile. Ask npm why the old package is there.
npm explain gulp
npm explain graceful-fs2Fix
Upgrade or replace the package that depends on Gulp 3. If it is dead, remove it. Then reinstall from a clean tree so the lockfile is rebuilt.
rm -rf node_modules package-lock.json
npm install3Verify
No gulp 3 and no graceful-fs 3 remain in the tree.
npm ls gulp graceful-fsConfirmed by github.com
How do I stop it coming back?
- Keep gulp on a supported major version and read its release notes before a Node.js upgrade.
- Commit the lockfile and run npm ls on the build server so an old transitive package shows up early.
- Pin the Node.js version in .nvmrc or the engines field so CI and laptops agree.
- Move new style builds to the sass package; Node Sass is deprecated.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix