我有这个节点应用程序。它一直运行到重启服务器为止。现在,我收到一条我不理解的错误消息。我不明白的是如何从错误消息转到导致错误的代码部分。
该错误可能与cors或dhparam有关,这是我添加到应用程序中的最后一件事,但这只是一个猜测。我试图注释与一个或另一个相关的行,但错误仍然存在。
这是我的应用
const https = require("https"),
fs = require("fs"),
helmet = require("helmet");
const cors = require("cors");
const options = {
key: fs.readFileSync("/etc/letsencrypt/live/www.***.com/privkey.pem"),
cert: fs.readFileSync("/etc/letsencrypt/live/www.***.com/fullchain.pem"),
dhparam: fs.readFileSync("/var/www/html/***/stripe/sslcert/dh-strong.pem")
};
const express = require("express");
const app = express();
const { resolve } = require("path");
app.use(helmet());
app.use(cors());
// Copy the .env.example in the root into a .env file in this folder
const env = require("dotenv").config({ path: "./.env" });
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
app.use(express.static(process.env.STATIC_DIR));
app.use(
express.json({
// We need the raw body to verify webhook signatures.
// Let's compute it only when hitting the Stripe webhook endpoint.
verify: function(req, res, buf) {
if (req.originalUrl.startsWith("/webhook")) {
req.rawBody = buf.toString();
}
}
})
);
app.listen(4242, () => console.log(`Node server listening on port ${4242}!`));
https.createServer(options, app).listen(4343);
这是我看到的错误日志
> SyntaxError: Unexpected token import
> at createScript (vm.js:80:10)
> at Object.runInThisContext (vm.js:139:10)
> at Module._compile (module.js:616:28)
> at Object.Module._extensions..js (module.js:663:10)
> at Module.load (module.js:565:32)
> at tryModuleLoad (module.js:505:12)
> at Function.Module._load (module.js:497:3)
> at Function.Module.runMain (module.js:693:10)
> at startup (bootstrap_node.js:188:16)
> at bootstrap_node.js:609:3 /usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:29
> import(process.env.pm_exec_path);
> ^^^^^^
注意:我正在使用PM2启动节点服务器