自定义框架vega使用

在Angular7框架中使用vega相关库的时候一直报如下错误:
ERROR in node_modules/vega-embed/src/embed.ts(2,8): error TS1192: Module ''json-stringify-pretty-compact'' has no default export.
node_modules/vega-lite/build/src/util.d.ts(1,8): error TS1192: Module '"E:/gitworks/stomach/node_modules/@types/json-stable-stringify/index"' has no default export.

检查vega-embed包和vega-lite包均安装正确

最后通过在tsconfig.json文件中加入如下语句解决:
"allowSyntheticDefaultImports": true,

原理:
"allowSyntheticDefaultImports": true语句的用处是允许从没有设置默认导出的模块中默认导入

查看node_modules/vega-embed/src/embed.ts文件发现其导入问题如下:
import stringify from 'json-stringify-pretty-compact';

而相应插件的导出方式是:
module.exports = stringify
未设置默认导出

相关链接:
TS引用JS模块: https://blog.csdn.net/letterTiger/article/details/80596369
ts模块解析:https://www.tslang.cn/docs/handbook/modules.html

你可能感兴趣的:(自定义框架vega使用)