跳到主要内容

Vercel实用手册

Vercel Functions 运行时报错

转载自:https://community.vercel.com/t/deploying-typescript-serverless-functions/4029

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///var/task/api/book.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:268:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
at async d (/opt/rust/nodejs.js:9:19220)
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

请添加以下配置。

tsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node"
}
}