# How to access p5js functions when using ES6 modules

**URL:** https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359
**Category:** Coding Questions
**Created:** [May 28, 2020, 7:51am UTC](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359 "2020-05-28T07:51:44Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 28, 2020, 9:46am UTC](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359/2 "2020-05-28T09:46:41Z")

</div>

> [@dansumption](#):
>
> , into a namespace accessible from “p5.voronoi.js”?

That “p5.voronoi” library is meant for sketches using the “global mode” approach only:

> <https://github.com/Dozed12/p5.voronoi/blob/master/library/p5.voronoi.js>

It means at the very least your main “sketch.js” file gotta use the “global mode” approach as well.

> [@dansumption](#):
>
> I am trying to write an app using ES6 modules and the voronoi library, and in this environment all of the processing instance functions ( `background` , `stroke` , `random` , etc) are not in the module’s namespace.

If p5.js is loaded via `<script>`, it dumps itself on the global namespace & thus it can be accessed even by ES6 module files, as long as it finds **setup()** and/or **draw()** on the global namespace as well, like this: `window.setup = function () {}`

Here’s a p5.js global mode sketch example using ES6 module files:

> <https://gist.github.com/GoSubRoutine/da4939559d8b786df13f5694ea2edd30>
>
> There are more than three files. show original

---

_[View the full topic](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359)._
