# Require tracking.js sometimes works

**URL:** <https://talk.observablehq.com/t/require-tracking-js-sometimes-works/9512>\
**Category:** Help\
**Created:** [July 17, 2024, 6:53am UTC](https://talk.observablehq.com/t/require-tracking-js-sometimes-works/9512 "2024-07-17T06:53:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndySmee](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/andysmee/32/9051_2.png) [@AndySmee](https://talk.observablehq.com/u/AndySmee)\
**Post date:** [July 17, 2024, 6:53am UTC](https://talk.observablehq.com/t/require-tracking-js-sometimes-works/9512/1 "2024-07-17T06:53:24Z")

</div>

> **[Require tracking.js problem](https://observablehq.com/d/fa9469d98840e6fe)**
>
> Sometimes it works (image above), the next load it doesn't (image below) Here's the code:

I have a require which works one minute and not the next. Can anyone diagnose, please. Notebook isolating the problem, above.

Thanks

P.S. I’ve added import {requireCheck} from ‘@lopsae/require-utilities@306’ to check npm version and it’s ok. Bundle.run returns the code when i open in a browser tab. Any ideas?

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [July 17, 2024, 8:49am UTC](https://talk.observablehq.com/t/require-tracking-js-sometimes-works/9512/2 "2024-07-17T08:49:04Z")

</div>

`window.tracking.ColorTracker(['cyan'])` runs independently of the cell above, so if it runs before `require('https://bundle.run/tracking@1.1.3');` has loaded the module, you get an error.

A solution is to be more explicit about the dependency:

```js
Tracker = require('https://bundle.run/tracking@1.1.3');

```

```js
colors = (Tracker, await new window.tracking.ColorTracker(['cyan']));

```

or better:

```js
tracker = require("https://bundle.run/tracking@1.1.3").then(() => window.tracking)

```

then use it like so:

```js
new tracker.ColorTracker(['cyan'])

```
