0

My Node.js app run well before. I put this Node.js app aside for several months and return back to continue to develop it on a new machine. Error happens!!! Error information is as follows:

fs.js:27
const { Math, Object } = primordials;
                         ^

ReferenceError: primordials is not defined
    at fs.js:27:26
    at req_ (/Users/xiaoningchang/Documents/Code/udfinder/avdetector/node_modules/natives/index.js:143:24)
    at Object.req [as require] (/Users/xiaoningchang/Documents/Code/udfinder/avdetector/node_modules/natives/index.js:55:10)
    at Object.<anonymous> (/Users/xiaoningchang/Documents/Code/udfinder/avdetector/node_modules/graceful-ncp/node_modules/graceful-fs/fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)

And my package.json is:

{
  "name": "meminsight",
  "version": "0.0.1",
  "description": "JavaScript memory analyses",
  "repository": {
    "type": "git",
    "url": "https://github.com/Samsung/meminsight.git"
  },
  "dependencies": {
    "acorn": "3.1.0",
    "argparse": "0.1.15",
    "aspect-js": "^1.0.3",
    "callsites": "^2.0.0",
    "chai": "^4.1.2",
    "codemirror": "5.1.0",
    "cover": "0.2.9",
    "datatables": "^1.10.18",
    "ejs": "1.0.0",
    "escope": "1.0.1",
    "esotope": "1.4.5",
    "estraverse": "4.0.0",
    "execSync": "1.0.2",
    "expect.js": "^0.3.1",
    "express": "3.4.8",
    "fast-stats": "0.0.2",
    "finalhandler": "0.0.3",
    "graceful-ncp": "2.0.0",
    "grunt": "0.4.5",
    "jquery": "2.1.3",
    "jsonparse": "0.0.6",
    "line-by-line": "0.1.3",
    "line-reader": "^0.4.0",
    "log4js": "^2.3.11",
    "mkdirp": "0.5.0",
    "mocha": "^1.20.1",
    "multi-key-cache": "^1.0.2",
    "parse5": "2.1.5",
    "q": "1.2.0",
    "rewriting-proxy": "0.5.1",
    "rimraf": "2.2.8",
    "serve-static": "^1.14.1",
    "sloc": "^0.2.1",
    "temp": "0.8.1",
    "websocket": "^1.0.30",
    "wrench": "1.5.8"
  },
  "scripts": {
    "test": "(cat test/testSuite.txt | sed 's/^/test\\//' | xargs ./node_modules/.bin/mocha --reporter spec --harmony) && cd lifetime-analysis && ./gradlew cleanTest test && cd ..",
    "build": "grunt typescript"
  },
  "devDependencies": {
    "grunt-cli": "0.1.13",
    "grunt-exec": "^0.4.6",
    "grunt-simple-mocha": "0.4.0",
    "grunt-typescript": "^0.8.0",
    "jasmine": "^2.8.0"
  },
  "license": "Apache-2.0"
}

It seems that something wrong in the the dependent module natives. However, according to the package.json file, the app do not rely on natives module. In addition, there is not variable named primordials in index.js file of natives module.

Additonal information: Version of Node.js: 12.10.0; Version of npm: 6.11.3; I also encounter an error that gyp ERR! build error when I npm install the app. I use the command npm audit fix to fix it. Is this related to my issue?

Could anyone help me about this issue? I am new to Node.js and have less experience to debug out of myself codes. Thanks a lot.

xiaoning
  • 41
  • 4
  • Your new machine, has the same OS than your old machine? It is a server machine, or your local development one? Did you try to `rm -rf node_modules; npm install` yet? The node version is the same? – Sergeon Oct 10 '19 at 14:38
  • Have you tried general solutions like `npm i` and updating Node and npm? It seems like a native module is trying to extract a property from an undeclared variable which obviously isn't your problem. – Mohammed Mortaga Oct 10 '19 at 14:40
  • @Sergeon The OS are different. I am not sure whether the version of node is same. I just `rm -rf nodule_modules` and `npm install` but the same error appears again. – xiaoning Oct 10 '19 at 14:44
  • @MohammedMortaga. I just `rm -rf node_modules` and `npm i`. But the same issue appears again. – xiaoning Oct 10 '19 at 14:46
  • @Sergeon I just check the version of Node on my previous machine, which is 11.6.0. Is the verison of node related to my issue? – xiaoning Oct 10 '19 at 14:50
  • Sometimes your Node version can make a whole lot of difference especially when it comes to transpilers and other modules. Try playing around with your Node and npm version, I'm sure you'll get somewhere. Good luck! – Mohammed Mortaga Oct 10 '19 at 14:52
  • Possible duplicate of [How to fix ReferenceError: primordials is not defined in node](https://stackoverflow.com/questions/55921442/how-to-fix-referenceerror-primordials-is-not-defined-in-node) –  Nov 02 '19 at 16:52

1 Answers1

1

The natives npm package is deprecated: https://www.npmjs.com/package/natives.

If you go its page, they warn about that the package may break in future node versions -- they seriously suggest against using the package in the first place, too. I guess either a different OS or node version is the culprit here. The fact that you don't have natives listed in your package.json as dependency, means that at least one of your dependencies is using natives -or a dependency of one of your dependencies and so on...-.

One way you can check which dependencies are using natives is to run:

$ npm ls natives

I installed your dependencies in a project in my local machine -MacOS 10- and run it, and it appears that graceful-fs is using natives. graceful-fs is a dependency of graceful-ncp, which is listed in your package.json.

When I did $npm install I got several warnings, one of them about upgrading graceful-fs to version 4 to avoid future errors when upgrading node version.

The graceful-ncp package is currently on version 3.0.0, so I upgraded the version in package.json to 3.0.0. Then $ rm -rf node_modules && npm i;

After that, $ npm ls natives yields empty, which means upgrading graceful-ncp version should fix your problem - of course, you may need to add changes to your code to avoid breaking changes of graceful-ncp.

Sergeon
  • 6,638
  • 2
  • 23
  • 43