我收到以下错误,我的节点版本是:12.18 当我运行npm start开始我的项目时
fs.js:36
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:36:5
有人回答说它是与吞咽和节点12(How to fix ReferenceError: primordials is not defined in node)有关的问题
但是我没有在项目中使用gulp,也没有安装gulp。
下面是我的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"
}
}
和我的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);
});
答案 0 :(得分:1)
如果您查看错误消息中没有提供的堆栈跟踪信息:
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)
您会发现错误源自natives
模块。运行npm ls natives
,您可以确定它是express-handlebars
的子依赖项:
myapp@1.0.0 C:\Users\Patrick\Desktop\test
`-- express-handlebars@2.0.1
`-- graceful-fs@3.0.12
`-- natives@1.1.6
您的express-handlebars
依赖性已经过时。将其从^2.0.1
更新为^5.1.0
可以解决您的问题,但您实际上不应忽略其余audit messages:
found 146 vulnerabilities (80 low, 15 moderate, 51 high)
run `npm audit fix` to fix them, or `npm audit` for details
答案 1 :(得分:0)
在项目根文件夹中创建一个名为 npm-shrinkwrap.json 的文件。
将代码添加到文件中:
{
"dependencies": {
"graceful-fs": {
"version": "4.2.2"
}
}
}