vue-codemirror 格式化SQL语句 及 使用sql-formatter插件Cannot read properties of undefined (reading ‘format‘) 报错

vue-codemirror 格式化SQL语句

配合sql-formatter插件

  1. 安装sql-formatter
// npm
npm install --save sql-formatter@2.3.3
// yarn
yarn add sql-formatter@2.3.3

  1. 在需要使用的页面引入 sql-formatter
import sqlFormatter from "sql-formatter"
//使用
var str = "CREATE TABLE IF NOT EXISTS `test_user`.`testA_` (`hello` VARCHAR(255) COMMENT '你好',`word` VARCHAR(255) COMMENT '世界') COMMENT '测试'  STORED AS PARQUET"
let sql = sqlFormatter.format(str)

格式化前
在这里插入图片描述
格式化后
在这里插入图片描述

按以上命令安装sql-formatter不会出现Cannot read properties of undefined (reading ‘format’) 报错

如果使用一下命令 不指定sql-formatter版本 npm会安装最新的依赖包8.x.x

// npm
npm install --save sql-formatter
// yarn
yarn add sql-formatter

就会出现Cannot read properties of undefined (reading ‘format’) 报错
目前我是把版本降低为2.3.3就解决了 别的再高一点的版本没试过,但是这个光格式化也是够用了

猜你喜欢

转载自blog.csdn.net/double_Fly_/article/details/126146625