gpt4 book ai didi

node.js - 我收到错误 : fs. js:36 } = primordials; ^ ReferenceError: 未定义原语

转载 作者:行者123 更新时间:2023-12-03 12:17:47 35 4
gpt4 key购买 nike

我收到以下错误,我的 Node 版本是:12.18
当我运行 npm start 开始我的项目时

 fs.js:36
} = primordials;
^

ReferenceError: primordials is not defined
at fs.js:36:5
有人回答说 gulp 和 Node 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);
});

最佳答案

如果您查看未提供的错误消息中的堆栈跟踪:

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

关于node.js - 我收到错误 : fs. js:36 } = primordials; ^ ReferenceError: 未定义原语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63711192/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com