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

如何修复在Vercel上运行Nuxt SSR时出现的构建错误

Vercel部署Nuxt SSR项目构建失败问题

错误信息

Command failed with exit code 1: npx nuxt build --standalone --no-lock --config-file "nuxt.config.js" /vercel/path0

22:49:04.071    
22:49:04.071    135 packages are looking for funding
22:49:04.071      run `npm fund` for details
22:49:04.100    [info] Install devDependencies took: 15238.448308 ms
22:49:04.101    [log]  ----------------- Nuxt build ----------------- 
22:49:04.461    [log] Running nuxt build --standalone --no-lock --config-file "nuxt.config.js" /vercel/path0
22:49:07.093    node:internal/crypto/hash:71
22:49:07.093      this[kHandle] = new _Hash(algorithm, xofLen);
22:49:07.094                      ^

错误堆栈截图

项目依赖配置

"dependencies": {
    "@nuxtjs/axios": "^5.13.6",
    "@nuxtjs/dotenv": "^1.4.1",
    "@nuxtjs/moment": "^1.6.1",
    "@nuxtjs/pwa": "^3.3.5",
    "@nuxtjs/vercel-builder": "^0.22.1",
    "@webzlodimir/vue-bottom-sheet": "^1.3.0",
    "add": "^2.0.6",
    "cookie-universal-nuxt": "^2.2.2",
    "cookieparser": "^0.1.0",
    "core-js": "^3.26.1",
    "moment": "^2.29.4",
    "nuxt": "^2.15.8",
    "nuxt-tailvue": "^1.0.95",
    "vue": "^2.6.14",
    "vue-currency-input": "^3.0.0",
    "vue-server-renderer": "^2.6.14",
    "webpack": "^4.46.0",
    "yarn": "^1.22.19"
  },
  "devDependencies": {
    "@nuxt/postcss8": "^1.1.3",
    "@nuxtjs/tailwindcss": "^4.2.1",
    "autoprefixer": "^10.4.8",
    "postcss": "^8.4.16",
    "tailwindcss": "^3.1.8",
    "vue": "^2.6.14",
    "vue-template-compiler": "^2.6.14"
  }

补充说明

有一个配置完全相同的项目可以正常运行,但新建SSR项目执行nuxt start命令时出现上述错误。


解决方案

从错误栈来看,node:internal/crypto/hash的报错大概率是Node.js版本不兼容导致的。Nuxt 2.15.8对Node.js版本有明确要求,建议使用Node.js 14.x或16.x(LTS版本),过高的Node.js版本(如18+)会和Nuxt 2的依赖产生兼容性冲突。

具体修复步骤:

  1. 指定Node.js版本

    • 在项目根目录创建.nvmrc文件,写入16或14:
      16
      
    • 或者在package.json中添加engines字段:
      "engines": {
        "node": "14.x || 16.x"
      }
      

    Vercel会自动读取配置,使用对应版本构建。

  2. 清理依赖缓存

    • 本地删除node_modules和锁文件,重新安装依赖:
      rm -rf node_modules package-lock.json yarn.lock
      npm install
      
    • 部署到Vercel时,在项目设置中开启"重新构建并清除缓存",避免旧缓存干扰。
  3. 调整依赖

    • 移除dependencies中的yarn和webpack:前者无需作为项目依赖,后者Nuxt 2已内置适配版本,手动指定易引发冲突。
    • 尝试升级@nuxtjs/vercel-builder到适配Nuxt 2的最新版本(如0.25.0),更新后重新安装依赖再部署。

按上述步骤调整后,重新部署即可解决构建失败问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 22:40:44