
该错误通常由 Node.js 版本过低导致——createSSRApp 自 Vue 3.2 起引入,但需 Node.js ≥ 16.14(推荐 ≥ 18)才能正确解析 ESM 模块及 Vue 的条件导出逻辑。升级 Node.js 至 v18.19.0 可彻底解决此问题。
该错误通常由 node.js 版本过低导致——createssrapp 自 vue 3.2 起引入,但需 node.js ≥ 16.14(推荐 ≥ 18)才能正确解析 esm 模块及 vue 的条件导出逻辑。升级 node.js 至 v18.19.0 可彻底解决此问题。
在构建 Vue 3 服务端渲染(SSR)应用时,调用 import { createSSRApp } from 'vue' 报错 SyntaxError: The requested module 'vue' does not provide an export named 'createSSRApp',根本原因并非 Vue 版本不足(你已安装 vue@^3.4.5),而是 Node.js 运行时无法正确识别 Vue 包中基于 exports 字段的条件导出机制。
Vue 3.2+ 将 SSR 相关 API(如 createSSRApp、renderToString)统一收口至 ESM 条件导出,其 package.json 中定义了类似如下结构:
{
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js"
},
"./server-renderer": {
"import": "./dist/server-renderer.mjs",
"require": "./dist/server-renderer.cjs"
}
}
}Node.js 14(如你使用的 14.15.2)对 exports 字段支持不完整,尤其在 "type": "module" 项目中,会跳过 ESM 入口或错误解析导出,导致 createSSRApp 不可见。
✅ 正确解决方案:升级 Node.js
立即学习“前端免费学习笔记(深入)”;
- 推荐版本:Node.js v18.19.0 或更高(LTS)
- 验证方式:
node -v # 应输出 v18.19.0 或类似 npm list vue # 确保 vue@3.4.5 已安装
升级后,你的 example.js 即可正常运行:
// example.js —— 现在可直接执行:node example.js
import { createSSRApp } from 'vue'
import { renderToString } from 'vue/server-renderer'
const app = createSSRApp({
data: () => ({ count: 1 }),
template: `<button @click="count++">{{ count }}</button>`
})
renderToString(app).then(html => {
console.log(html) // 输出:'<button>1</button>'
})⚠️ 额外注意事项:
- 不要降级 Vue 版本试图“兼容旧 Node”——Vue 3.4 已完全弃用 Node.js 14 支持;
- 若使用 pnpm/yarn,请在升级 Node 后重新安装依赖(
pnpm install),避免缓存残留; - 生产 SSR 服务(如 Express 集成)中,还需确保服务端入口使用
createSSRApp,客户端挂载使用createApp,二者不可混用。
总结:Vue SSR 的模块化能力深度依赖现代 Node.js 的 ESM 实现。保持 Node.js 与 Vue 版本协同演进,是规避此类“API 不存在”类错误的关键前提。


















