# Setup method runs twice

**URL:** <https://discourse.processing.org/t/setup-method-runs-twice/21275>\
**Category:** Coding Questions\
**Created:** [May 25, 2020, 11:30am UTC](https://discourse.processing.org/t/setup-method-runs-twice/21275 "2020-05-25T11:30:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)\
**Post date:** [May 25, 2020, 11:30am UTC](https://discourse.processing.org/t/setup-method-runs-twice/21275/1 "2020-05-25T11:30:39Z")

</div>

My p5js app runs the `setup` function twice. I have stripped the whole thing down as much as possible, and it’s still happening. This is messing with my app because (a) I wish to run some fairly heavy operations in setup and (b) I add some objects to an array in setup, and if it runs twice then the objects are doubled up.

My `index.js` looks like this:

```auto
const sketch = (processing) => {
  processing.setup = () => {
    console.log('run setup');
  };
};
const myProcessing = new p5(sketch);

```

…and my `index.html` looks like this:

```auto
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>vis-p5js</title>
</head>
<body>
  <div id="test"></div>
</body>
<script src="./lib/p5.js"></script>
<script src="./lib/p5.sound.js"></script>
<script type="module" src="./src/index.js"></script>
</html>

```

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [May 25, 2020, 12:01pm UTC](https://discourse.processing.org/t/setup-method-runs-twice/21275/2 "2020-05-25T12:01:34Z")

</div>

Hello and welcome, @dansumption!

I can’t reproduce this locally. `setup` is only called once when running on p5.js 1.0.0. Could you host a complete example online for us to try? Is the problem present if you try another browser? Which version of p5.js are you on?

---

<div class="post-metadata">

**Author:** ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)\
**Post date:** [May 25, 2020, 5:47pm UTC](https://discourse.processing.org/t/setup-method-runs-twice/21275/3 "2020-05-25T17:47:45Z")

</div>

Hi Sven,

Thanks for checking this out.

Strange, I have version 1.0.0 here too.

I’ll stick a version online when I get a chance, as well as trying some more browsers. Have been running it in Chrome.

---

<div class="post-metadata">

**Author:** ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)\
**Post date:** [July 2, 2020, 6:36pm UTC](https://discourse.processing.org/t/setup-method-runs-twice/21275/4 "2020-07-02T18:36:17Z")

</div>

In case anyone else encounters this problem, I finally managed to solve it, and it was down to the way that I wasn instantiating processing and assigning the `setup` and `draw` methods. I’ve documented it in this thread: [How to access p5js functions when using ES6 modules](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359/)
