How to fix ReferenceError: primordials is not defined in node

廉价感情. 提交于 2019-11-26 08:02:10

问题


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:


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`



回答4:


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




回答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:


Downgrading to node stable fixed this issue for me, as it occurred after I upgraded to node 12

sudo n 10.16.0




回答7:


We encountered the same issue on a legacy project using gulp@3.9.1. The fix was to force graceful-fs@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. Note that this is not a perennial solution but it helps when you don't have time to update to gulp@^4.0.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:


Upgrade to 4.0.1 and make sure to migrate https://fettblog.eu/gulp-4-parallel-and-series/#migration




回答11:


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




回答12:


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



回答13:


What worked for me was to use python2 during npm installation.

npm install --python=~/venv/bin/python




回答14:


For those who are using yarn.

yarn global add n
n 11.15.0
yarn install # have to install again



回答15:


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.




回答16:


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.




回答17:


uninstall node and reinstall it using given link. https://nodejs.org/en/download/



来源:https://stackoverflow.com/questions/55921442/how-to-fix-referenceerror-primordials-is-not-defined-in-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!