Uncaught TypeError: p5 is not a constructor

Uncaught TypeError: p5 is not a constructor

我在启动 p5js 时遇到了一些问题,因为我收到了这个错误:

Uncaught TypeError: p5 is not a constructor

import * as p5 from 'p5';
export default {
    init() {
        //a P5 moire pattern.
        let s = (sk) => {
            let layers = [];

            // sk.translate(window.innerWidth/2,window.innerHeight/2);
            sk.setup = () =>{
                let gfx = sk.createGraphics(window.innerWidth, window.innerHeight);
                let gfx2;

                sk.createCanvas(window.innerWidth, window.innerHeight);
                sk.angleMode(sk.DEGREES);
                sk.imageMode(sk.CENTER);
                sk.translate(window.innerWidth/2, window.innerHeight/2);
                sk.background(40);
                gfx.stroke(200);
                gfx.strokeWeight(3);
                gfx.line(0, 0, window.innerWidth, 0);
                for(let i=0; i<1000; i++){
                    gfx.point(Math.random() *window.innerWidth, Math.random() *window.innerHeight);
                }

                gfx2 = {...gfx};
                sk.image(gfx,0,0);
                sk.rotate(1);
                sk.image(gfx2,0,0);
            }

        }
        const P5 = new p5(s, document.getElementById('grid'));
    }
}

我的目的地 index.js 对象刚刚初始化为 myObject.init()index.html 中有一个 div#grid。 我看不出这个问题。任何帮助将不胜感激。

对于遇到相同问题的任何人,我理所当然地(遵循 p5js 文档和有关库的其他资源)像 import * as p5 from 'p5' 这样的导入是正确的,但它是一个命名的导出 class 所以你需要至 import p5 from 'p5'。成功了。

编辑:单词。