I get the following error, my node version is: 12.18 when I run npm start to start my project
 fs.js:36
  } = primordials;
^
ReferenceError: primordials is not defined
at fs.js:36:5
someone answered that its problem with gulp and node 12 (How to fix ReferenceError: primordials is not defined in node)
but I don't use gulp in my project and I don't have gulp installed.
below is my package.json
{
    "name":"myapp",
    "version":"1.0.0",
    "description":"",
    "scripts":{
        "start":"node server.js",
        "test":"echo \"Error: no test specified\" && exit 1"
    },
    "author":"MJX",
    "license":"ISC",
    "dependencies":{
        "body-parser":"^1.19.0",
        "express":"^4.17.1",
        "express-handlebars":"^2.0.1",
        "mssql":"^6.2.1",
        "mysql":"^2.18.1",
        "nodemon":"^1.19.4",
        "npm":"^5.10.0"
    },
    "devDependencies":{
        "handlebars-helper-css":"^0.1.0"
    }
}
and my server.js:
var express = require("express");
var bodyParser = require("body-parser");
var PORT = process.env.PORT || 4300;
var app = express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var exphbs = require("express-handlebars");
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
var routes = require("./controllers/burgersController.js");
app.use(routes);
app.listen(PORT, function() {
    console.log("App now listening at localhost:" + PORT);
});
If you look at the stack trace in your error message that you didn't provide:
ReferenceError: primordials is not defined
    at fs.js:35:5
    at req_ (C:\Users\Patrick\Desktop\test\node_modules\natives\index.js:143:24)
    at Object.req [as require] (C:\Users\Patrick\Desktop\test\node_modules\natives\index.js:55:10)
    at Object.<anonymous> (C:\Users\Patrick\Desktop\test\node_modules\graceful-fs\fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
you'll find that the error originates from the natives module. Running npm ls natives, you can determine that it's a sub-dependency of express-handlebars:
[email protected] C:\Users\Patrick\Desktop\test
`-- [email protected]
  `-- [email protected]
    `-- [email protected]
Your express-handlebars dependency is extremely outdated. Updating it from ^2.0.1 to ^5.1.0 fixes your problem, but you really shouldn't ignore the rest of your audit messages:
found 146 vulnerabilities (80 low, 15 moderate, 51 high)
  run `npm audit fix` to fix them, or `npm audit` for details
Create a file named npm-shrinkwrap.json in the project root folder.
Add the following code to the file:
{
   "dependencies": {
      "graceful-fs": {
         "version": "4.2.2"
      }
   }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With