Require tracking.js sometimes works

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?

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:

Tracker = require('https://bundle.run/tracking@1.1.3');
colors = (Tracker, await new window.tracking.ColorTracker([ 'cyan']));

or better:

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

then use it like so:

new tracker.ColorTracker([ 'cyan'])
1 Like