Are you getting a ReferenceError: primordials is not defined
error message when trying to run gulp? Chances are you're on gulp v3
and node v12
, and that's the source of the issue.
The thing is, gulp v3
doesn't work (as of now) under node v12
, because it depends on graceful-fs@^3.0.0
which patches Node's fs
module and that patch worked before node v12
just fine.
So our options are either:
a) To upgrade gulp
to v4 - to me, that's not an option, and I don't want to re-write and re-config my frontend toolchain for Xth time. b) To downgrade Node
to v11 - is also not an option to me, I don't want to jump through nvm
hoops or even think about juggling node environments c) To pin graceful-fs
to version 4.2.2
that's known to work under Node v12
- that's the option I've chosen, let me tell how to use it.
To pin graceful-fs
to version 4.2.2
, we need to use an npm-shrinkwrap.json
file, which lets you lock down the versions of installed packages and their descendant packages. Anything specified in this file can't be overridden by package.json
content, which gives us what we need: pinning graceful-fs
at 4.2.2
despite whatever gulp 3
requires in package.json
.
Here's what you need to do:
-
In the same directory where you have
package.json
create annpm-shrinkwrap.json
file with the following contents:jsoncopy
{ "dependencies": { "graceful-fs": { "version": "4.2.2" } } }
-
Run
npm install
, and don't worry, it'll updatenpm-shrinkwrap.json
with a bunch of content.
Now, fire your gulp
command and enjoy, it should be working just fine!
受到上面解决方案的启发。安装了[email protected]。然后删掉node_modules目录里之前版本的graceful-fs。在运行npm就不会报错了。