可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have installed node modules by npm install, then I tried to do gulp sass-watch in command prompt. After that I got the below response.
[18:18:32] Requiring external module babel-register
fs.js:27
const { Math, Object, Reflect } = primordials;
^
ReferenceError: primordials is not defined
Have tried this before gulp sass-watch
npm -g install gulp-cli
回答1:
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.
回答2:
Use following commands and install node v11.15.0:
npm install -g n
sudo n 11.15.0
will solve
ReferenceError: primordials is not defined in node
Referred from @Terje Norderhaug @Tom Corelis answers.
回答3:
We encountered the same issue when updating a legacy project depending on gulp@3.9.1
to Node.js 12.
The solution
This fix enables you to use Node.js 12 with gulp@3.9.1
by overriding graceful-fs
to version 4.2.2
using a npm-shrinkwrap.json
file containing this:
{
"dependencies": {
"graceful-fs": {
"version": "4.2.2"
}
}
}
And then executing npm install
which will update the npm-shrinkwrap.json
file.
Additional info
This issue stems from the fact that gulp@3.9.1
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.
Note that this is not a perennial solution but it helps when you don't have time to update to gulp@^4.0.0
.
回答4:
Using NVM to manage what node version you're using, running the following commands worked for me:
$ cd /to/your/project/
$ nvm install lts/dubnium
$ nvm use lts/dubnium
$ yarn upgrade # or `npm install`
回答5:
Use following commands to install node v11.15.0
and gulp v3.9.1
:
npm install -g n
sudo n 11.15.0
npm install gulp@^3.9.1
npm install
npm rebuild node-sass
Will solve this issue:
ReferenceError: primordials is not defined in node
回答6:
had same error and finally fix that when updated all packages and then mentioned the same node engine version and npm version in package.json
as it is in my local working system.
"engines": {
"node": "10.15.3",
"npm": "6.9.0"
}
i was getting this error when deploying on heroku.
for more checkout heroku support
回答7:
Downgrading to node stable fixed this issue for me, as it occurred after I upgraded to node 12
sudo n 10.16.0
回答8:
Gulp 3.9.1 doesn't work with Node v12.x.x, and if you upgrade to Gulp 4.0.2, you have to completely change gulpfile.js with the new Syntax (Series & Parallels). So your best bet is to downgrade to Node V 11.x.x, the 11.15.0 worked fine for me. By simply using the following code in terminal:
nvm install 11.15.0
nvm use 11.15.0 #just in case it didn't automatically select the 11.15.0 as the main node.
nvm uninstall 13.1.0
Cheers!
回答9:
I was getting this error on Windows 10. Turned out to be a corrupted roaming profile.
npm ERR! node v12.4.0
npm ERR! npm v3.3.12
npm ERR! primordials is not defined
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
Deleting the C:\Users\{user}\AppData\Roaming\npm
folder fixed my issue.
回答10:
This might have come in late but for anyone still interested in keeping their Node v12 while using the latest gulp ^4.0, follow these steps:
Update the command-line interface (just for precaution) using:
npm i gulp-cli -g
Add/Update the gulp
under dependencies section of your package.json
"dependencies": {
"gulp": "^4.0.0"
}
Delete your package-lock.json
file
Delete your node_modules
folder
Finally, Run npm i
to upgrade and recreate brand new node_modules folder and package-lock.json file with correct parameters for Gulp ^4.0
npm i
Note Gulp.js 4.0 introduces the series()
and parallel()
methods to combine tasks instead of the array methods used in Gulp 3, and so you may or may not encounter an error in your old gulpfile.js
script.
To learn more about applying these new features, this site have really done justice to it: https://www.sitepoint.com/how-to-migrate-to-gulp-4/
(If it helps, please leave a thumps up)
回答11:
I fixed this issue on Windows 10 by uninstalling node from Add or remove programs -> Node.js
Then I installed version 11.15.0 from https://nodejs.org/download/release/v11.15.0/
Choose node-v11.15.0-x64.msi if your running windows 64bit.
回答12:
For those who are using yarn
.
yarn global add n
n 11.15.0
yarn install # have to install again
回答13:
Upgrade to 4.0.1 and make sure to migrate https://fettblog.eu/gulp-4-parallel-and-series/#migration
回答14:
I faced the same issue.
What i tried and worked for me:-
1). Check the version of NODE and GULP (combination of node v12 and gulp less than v4 doesn't work)
2). I downgrade npm version by :
#sudo npm install -g n
#sudo n 10.16.0
It worked fine, then just follow instruction of your consol
回答15:
i have same problem, but i have solved this problem. i suggest you first, first make sure npm install your not problem. then you downgrade version node and gulp. i used version node 10.16.1 and gulp 3.9.1.
for downgrade your gulp you can write
npm install gulp@^3.9.1
回答16:
What worked for me was to use python2 during npm installation.
npm install --python=~/venv/bin/python
回答17:
as we also get this error when we use s3 npm package. so the problem is with graceful-fs package we need to take it updated. it is working fine on 4.2.3.
so just look in what npm package it is showing in logs trace and update the graceful-fs accordingly to 4.2.3.
回答18:
For anyone having same error for the same reason in ADOS CI Build:
This question was the first I found when looking for help.
I have an ADOS CI build pipeline where first Node.js tool installer task is used to install Node. Then npm task is used to install gulp (npm install -g gulp). Then the following Gulp task runs default-task from gulpfile.js. There's some gulp-sass stuff in it.
When I changed the Node.js tool to install 12.x latest node instead of an older one and the latest gulp version was 4.0.2. The result was the same error as described in the question.
What worked for me in this case was to downgrade node.js to latest 11.x version as was already suggested by Alphonse R. Dsouza and Aymen Yaseen. In this case though there's no need to use any commands they suggested, but rather just set the Node.js tool installer version spec to latest Node version from 11.x.
The exact version of Node.js that got installed and is working was 11.15.0. I didn't have to downgrade the Gulp.
回答19:
I was also getting error on Node 12/13 with Gulp 3, moving to Node 11 worked
回答20:
I Hit this error after upgrading my node to version 12, which doesn't work with Gulp 3.9.1. Regarding the fact that my gulpfile.js wasn't so complex, I decided to upgrade to Gulp 4 using this article, It went well, and is was much easier than I thought.
回答21:
You Have Two Option Here
- Either upgrade to gulp 4 Or Else
- downgrade to an earlier node version.
回答22:
solved by downgrading node.js version from 12.14.0
to 10.18.0
and reinstalling node_modules
回答23:
if you're trying to install semantic-ui
and the following error occurs then try downloading the latest version of node js(13.5.0)
with the latest features, from nodejs.org, Moreover rather than trying npm install semantic you should just add the link(which you can find from cdnjs link to the header of your index.html
file.
Best of luck!
回答24:
Are You Facing ReferenceError: primordials is not defined Error when trying to run gulp? Maybe 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.
Solution for ReferenceError: primordials is not defined:
upgrade gulp to v4 . This Solution Will Solve Your Error.
To downgrade Node to v11 To Solve This Error.
To pin graceful-fs to version 4.2.2 that’s known to work under Node v12 – That Option Explained Below This Option Is Worked for me So I recommend you this Option.
Here Is Example Of Option 3
回答25:
uninstall node and reinstall it using given link.
https://nodejs.org/en/download/