zrender TypeError: “x“ is not a constructor

If you are interested in learning more about it, please visit my personal website: Yetong Space

I am calling the init method of zrender to report an error, as shown below:
insert image description here

Then, after being pointed out by the boss, this kind of development environment is fine, but the production environment reports an error, usually because it was dropped by tree-shaking during packaging.

After debugging+ looking at the source code, it is found that the registerPainter method is missing.
insert image description here

Imitate the source code to call:
insert image description here

import {
    
     init } from "zrender";
import {
    
     registerPainter } from 'zrender';
import CanvasPainter from 'zrender/lib/canvas/Painter';
import SVGPainter from 'zrender/lib/svg/Painter';
registerPainter('canvas', CanvasPainter);
registerPainter('svg', SVGPainter);

problem solved. What an amazing experience.

By the way, this project is already online and open source, address: http://stars.eyescode.top

Guess you like

Origin blog.csdn.net/tongkongyu/article/details/129222069