【问题标题】:TypeError: vue.openBlock is not a function, while using vue component from custom node moduleTypeError:vue.openBlock 不是函数,同时使用自定义节点模块中的 vue 组件
【发布时间】:2025-12-09 19:20:04
【问题描述】:

我创建了支持 vue 的自定义节点模块。

Package.json

{
 "name": "test-node-module",
 "version": "1.0.0",
 "description": "",
 "main": "./dist/index",
 "scripts": {
   "dev": "vue serve test.vue",
   "test": "echo \"Error: no test specified\" && exit 1"
 },
 "author": "Sam",
 "license": "ISC",
 "devDependencies": {
   "@vue/compiler-sfc": "^3.0.0-beta.15",
   "bili": "^5.0.5",
   "rollup-plugin-vue": "^6.0.0-beta.6",
   "vue-template-compiler": "^2.6.11"
 }
}

index.js

import test from "./test.vue"

 export default {
   install(Vue, options) {
     Vue.component("test", test);
   }
 }

test.vue 有简单的文字。

在我项目的 ma​​in.js

import Test from "test-node-module"

Vue.use(Test)

使用组件<test></test> 会出现这样的错误。

[Vue warn]: Error in render: "TypeError: vue.openBlock is not a function"

在自定义节点结节中,dist/index.js 文件是这样的。

'use strict';

 var vue = require('vue');

 var script = {};

 function render(_ctx, _cache) {
   return (vue.openBlock(), vue.createBlock("div", null, " Test123 "))   // Error is here...
 }

 script.render = render;

 var index = {
   install: function install(Vue, options) {
     Vue.component("test", script);
   }
 };

 module.exports = index;

我该如何解决这个问题?我错过了什么吗?

【问题讨论】:

    标签: javascript vue.js node-modules


    【解决方案1】:

    rollup-plugin-vue 的最新版本需要 Vue 3 才能正常运行,而 Vue-cli 安装 Vue v2。有 2 个选项:在您的项目中安装 Vue 3 或使用旧版本的 rollup-plugin-vue

    目前 5.0.0 版适用于我:

    "rollup-plugin-vue": "5.0.0",
    

    这是包的已知问题,尚未收到官方回复 https://github.com/vuejs/rollup-plugin-vue/issues/363

    【讨论】: