That's the way you import it that causes the problem.
You should import it by typing:
import 'p5';
Then declare a variable:
private p5;
You should now be able to do something like this:
ngOnInit() {
this.createCanvas();
}
private createCanvas() {
this.p5 = new p5(this.sketch);
}
private sketch(p: any) {
p.setup = () => {
p.createCanvas(700, 600);
};
p.draw = () => {
p.background(255);
p.fill(0);
p.rect(p.width / 2, p.height / 2, 50, 50);
};
}
Here's my ng version :
Angular CLI: 1.7.4
Node: 9.11.1
OS: win32 x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0
and last version of p5 in package.json:
"p5": "^0.6.1"
Everything's working fine for me.
Hope it will help.