Tensorflow.js latest version packing and version 1 - Observable Framework

Hi,

What’s the difference in packing between Tensorflow.js version 1 and the latest version?

I try to use Tensorflow.js in Observablehq framework. Version number 1 works fine but latest don’t? It gives error message…

TypeError: t.alea is not a function
RuntimeError: t.alea is not a function

//WORKS!
import * as tf from 'npm:@tensorflow/tfjs@1';

//DON'T WORK!
import * as tf from 'npm:@tensorflow/tfjs@latest';
// Define a simple model.
const model = tf.sequential();
model.add(tf.layers.dense({units: 100, activation: 'relu', inputShape: [10]}));
model.add(tf.layers.dense({units: 1, activation: 'linear'}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});

const xs = tf.randomNormal([100, 10]);
const ys = tf.randomNormal([100, 1]);

// Train the model.
model.fit(xs, ys, {
  epochs: 100,
  callbacks: {
    onEpochEnd: (epoch, log) => display(`Epoch ${epoch}: loss = ${log.loss}`)
  }
});

This error is encountered because the newer versions of TensorFlow.js changed their module bundling and dropped support for some global functions like t.alea() which were accessible before.
My recommendation here would be to either stick with the older version when using the Observable, as newer versions are designed for ESM-based environments.
Refer: Releases · tensorflow/tfjs · GitHub