You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vercel部署报错:Serverless Functions runtime无效(nodejs14.x)求助

问题:Vercel部署报错Serverless Functions runtime无效(nodejs14.x)

更新项目依赖包后,Vercel部署日志报错:“以下Serverless Functions包含无效runtime:index (nodejs14.x)”。本地和Vercel配置的都是Node 18,但项目文件中搜索不到与14相关的配置,请问涉及哪些函数?如何将runtime版本设置为18?

部署日志详情

[success] Generated /sitemap.xml
[info] Nuxt build took: 51263.316986 ms
[log]  ----------------- Install dependencies ----------------- 
yarn install v1.22.22
info No lockfile found.
[1/6] Validating package.json...
[2/6] Resolving packages...
[3/6] Fetching packages...
[4/6] Linking dependencies...
warning "@nuxtjs/sentry > @sentry/vue@7.110.1" has unmet peer dependency "vue@2.x || 3.x".
warning "nuxt-leaflet > vue2-leaflet@2.7.1" has unmet peer dependency "vue@^2.5.17".
warning " > vt-notifications@0.4.1" has unmet peer dependency "vue@^2.0.0".
warning " > vue-advanced-cropper@1.11.6" has unmet peer dependency "vue@^2.6.6".
warning "vue-ssr-carousel > bukwild-stylus-library@3.2.1" has unmet peer dependency "stylus@*".
warning "vue-ssr-carousel > bukwild-stylus-library > stylus-type-utils@0.0.3" has unmet peer dependency "stylus@0.x".
warning " > vuex-persist@3.1.3" has unmet peer dependency "vuex@>=2.5".
[5/6] Building fresh packages...
[6/6] Cleaning modules...
Done in 8.48s.
[info] Install dependencies took: 8706.237786 ms
[log]  ----------------- Collect artifacts ----------------- 
[info] Collect artifacts took: 17519.974892 ms
Build Completed in /vercel/output [3m]
Deploying outputs...
Error: The following Serverless Functions contain an invalid "runtime":
  - index (nodejs14.x). Learn More: https://vercel.com/guides/serverless-function-contains-invalid-runtime-error
解决方案

涉及的函数

报错中明确指向的是名为index的Serverless函数,对应项目中的文件路径通常为:

  • 常规Node项目:api/index.js(或.ts)
  • Nuxt项目:server/api/index.js(或.ts)

设置runtime为Node 18的方法

1. 单个函数文件指定runtime

在index函数文件的最顶部添加注释,强制指定runtime版本:

// @vercel/node@18
// 或直接标识runtime
// runtime: nodejs18.x

export default function handler(req, res) {
  // 函数业务逻辑
}

2. 全局配置(所有Serverless函数统一生效)

在项目根目录创建或修改vercel.json文件,添加全局runtime规则:

{
  "functions": {
    // 适配Nuxt项目的server目录结构
    "server/**/*.js": {
      "runtime": "nodejs18.x"
    },
    // 适配常规api目录结构的项目
    "api/**/*.js": {
      "runtime": "nodejs18.x"
    }
  }
}

3. 确认Vercel项目平台配置

登录Vercel控制台,进入对应项目的Settings -> General -> Node.js Version,确认已选择18.x版本,保存后重新触发部署。


内容的提问来源于stack exchange,提问作者Peter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 17:42:30