【发布时间】:2021-10-14 16:36:06
【问题描述】:
错误发生日志:
13:24:54:83
2021-08-11T07:54:55.292Z undefined ERROR (node:8) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
2021-08-11T07:54:55.303Z undefined ERROR /var/task/api/userLoginEmail.js:8
export default async function (req, res) {
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
at async Loader.import (internal/modules/esm/loader.js:177:24)
at async getListener (/var/task/___vc/__launcher.js:33:11)
RequestId: df65f579-7eb4-4d5b-8f43-ed01c4e5ecd1 Error: Runtime exited with error: exit status 1
Runtime.ExitError
即使在将 type: module 添加到 package json 之后,它也会因其他文件而中断,但类似的代码会通过而不记录任何日志?怎么可能只是为了这个?
这是其他文件的起始代码,它可以在没有任何错误日志的情况下工作
import Cookies from "cookies";
import { createEmailTemplate } from "./functions";
export default async function (req, res) {
// Create a cookies instance
const cookies = new Cookies(req, res);
// // Get a cookie
// LINE BELOW COMMENTED FOR VERCEL DEPLOYMENT TEST!
if (req.method !== "POST" && cookies.get("kAppToken") !== null &&
process.env.API_ACCESS_SECRET_TOKEN) return res.status(403).send(res.send("not allowed"));```
【问题讨论】:
标签: node.js import export package.json vercel