首页 > 其他分享 >Custom directive is missing corresponding SSR transform and will be ignored

Custom directive is missing corresponding SSR transform and will be ignored

时间:2023-06-16 15:11:36浏览次数:45  
标签:ignored corresponding directive SSR 指令 报错 vitepress 组件

背景

最近在给业务组件库集成指令库,将各个项目中常用的指令如一键复制、元素和弹窗拖拽等封装到一起,进行统一发版维护。
业务组件库项目架构采用的是pnpm+vite+vue3+vitepress,其中vitepress主要做组件库文档站点同时展示可交互的组件。

问题

开发运行时指令库demo没有问题,构建编译时就会报错,编译不通过,报错:
Custom directive is missing corresponding SSR transform and will be ignored

一番查找原因,发现是VitePress应用在生成静态构建时是通过Node.js服务端渲染的,识别不了我们的包含
自定义指令的组件。

解决方式

一番搜索和chatgpt问答后,参考了https://blog.csdn.net/theoneEmperor/article/details/114087464,在vite.config.ts中进行配置,
还是构建编译不过,反而产生新的错误,
又试过https://www.npmjs.com/package/patch-vue-directive-ssr库,这个,本地构建编译不报错了,但线上构建还是会报错
最后在官方vitepress文档中找到

使用或展示非SSR友好(比如包含自定义指令)的组件,可以使用 vitepress中的全局组件 ClientOnly将其包裹

<ClientOnly>
  <NonSSRFriendlyComponent />
</ClientOnly>

但包裹后,还是会构建不通过,官方文档没有明确的说明,还得进行如下配置才行:


//docs\.vitepress\config.ts  文件
...
const buildTransformers = () => {
  const transformer = () => {
    return {
      props: [],
      needRuntime: true,
    }
  }

  const transformers = {}
   // 自定义的指令要添加到该数组中
  const directives = [
    'yun-copy',    
    'yun-draggable',
    'yun-long-press',
    'yun-water-marker',
  ]
  directives.forEach((k) => {
    transformers[k] = transformer
  })

  return transformers
}

...
  vue: {
    template: {
      ssr: true,
      compilerOptions: {
        directiveTransforms: buildTransformers(),
      },
    },
  },
...

现在分享出来,希望对你有所帮助,记得点个赞哟~

标签:ignored,corresponding,directive,SSR,指令,报错,vitepress,组件
From: https://www.cnblogs.com/mrwh/p/17485595.html

相关文章

  • AngularJS directive入门例子
    这是《AngularJS》这本书里面提供的一个例子: JS代码:varexpanderModule=angular.module('expanderModule',[])expanderModule.directive('expander',function(){return{restrict:'EA',replace:true,transclude:true......
  • 八、流水线语法之Directives
    一、environmentenvironment指令指定了一系列键值对,这些键值对将被定义为所有步骤或阶段特定步骤的环境变量,具体取决于环境指令在管道中的位置。该指令支持一个特殊的助手方法credentials(),该方法可用于通过Jenkins环境中的标识符访问预定义的credentials。支持的凭据类型Secret......
  • Custom elements in iteration require 'v-bind:key' directives.
    Customelementsiniterationrequire'v-bind:key'directives.这个错误提示"Customelementsiniterationrequire'v-bind:key'directives"的意思是在循环中使用自定义元素时,需要为每个元素添加v-bind:key指令。......
  • [Warning] World-writable config file '/etc/my.cnf' is ignored
    告警信息,全局读写配置文件,那么就把权限调整小。 ......
  • 创建pv时报错:Device /dev/sdb not found (or ignored by filtering).
    创建pv时报错:[root@PC1~]#pvcreate/dev/sdbDevice/dev/sdbnotfound(orignoredbyfiltering).解决:执行命令:ddif=/dev/urandomof=/dev/sdbbs=512count=64[root@PC1~]#ddif=/dev/urandomof=/dev/sdbbs=512count=64记录了64+0的读入记录了64+0的写出3276......
  • K8s报错:[preflight] WARNING: JoinControlPane.controlPlane settings will be ignore
    一、报错信息[preflight]WARNING:JoinControlPane.controlPlanesettingswillbeignoredwhencontrol-planeflagisnotset.[preflight]Runningpre-flightcheckserrorexecutionphasepreflight:[preflight]Somefatalerrorsoccurred:[ERRORFileAvailabl......
  • 解决Some index files failed to download.They have been ignored, or old ones used
    使用pingwww.baidu.com测试一下网络,如果出现:ping:www.baidu.com:Temporaryfailureinnameresolution就是网络问题了以下是解决办法,修改两处后重启即可,下面详细说明第一处修改的地方:sudovim/etc/systemd/resolved.conf修改DNS如下:[Resolve]DNS=8.8.8.8#FallbackD......
  • uniapp directive 在原生 wgt 包不生效 uniapp directive 不生效
    需求根据权限编码禁用按钮阻止当前dom绑定的点击事件,禁用状态(opacity半透明??或者display:none??)尝试开发环境用Chrome跑,一切正常,构建打包后去真机跑,按钮没控制住(用HBX-发行-原生应用app制作wgt包)开发环境:HBX:3.7.9系统:MacOS:13.0.1(Intel)通过direct......
  • vue-input-directive 插件的使用(已兼容vue3.0)
    codepen体验地址github地址安装、引入npminstallvue-input-directive--saveimportVuefrom'vue'importinputValidatefrom'vue-input-directive'Vue.use(inputValidate)1、d-input-max 输入数字限制最大值<el-inputv-d-input-max="99.99"v-......
  • vue3 directive自定义指令
    importstorefrom'../store'//新建jsexportdefault{install(app){//权限控制,没有相关的权限,则删除模块app.directive('permission',{mounted(el,val){if(el&&!store.state.rule.includes(val.valu......