How to get p5js library into account in js parser


#1

Hi,
I use glitch with p5js library and your internal parser did’nt recognize the function name of p5js. Is there anyway to take a library into account during parsing ?
Best regards

Christophe


#2

if i am correct in that the issue is it’s looking for a global called “p5js”, you can add /* global p5js */ to the first line in the file to get rid of that error. if that doesn’t help, let me know the project name and I can check it out for you!


#3

Hi Jenn,

Here is my project. https://glitch.com/edit/#!/remix/p5jsplay
It use p5js library (https://p5js.org/) I declare this library in index.html file.
When I go, for example, in the sketch.js I got the error "createCanvas is not defined"
Is there a way to recognize this function name belonging to p5js library ?
Thanks for your help


#4

you would list all the variables that are not defined in that file/scope (see my remix at https://glitch.com/edit/#!/night-text?path=public/sketch.js:19:1)

and just so you know, the error is in the practice of using global variables, which happens to be necessary when using p5 like this - it’s not a programming error on your part!


#5

oh of course I knew this was’nt an error from glitch :wink:
I just wanted to know how to skip this error message.
Is there a way to include a js file with this global variables definitions ?
So my students will not be obliged to include such line in their program ?
Best regards


#6

You says "which happens to be necessary when using p5 like this"
Do you know an other way using p5 in glitch ?


#7

you can add p5 as a dependency in package.json and require it in your client side js - but you’d need to use something like browserify to get that “require” function


#8

OK Jenn
I’ll look at this solution.
Thanks for your help