Javascript import in node.js

I’m using the mljs library and I’m trying to figure out how to properly import for node.js.

In javascript it is:

`import { DecisionTreeClassifier as DTClassifier } from 'ml-cart';`

I tried in node.js:

const DecisionTreeClassifier= require('ml-cart');

but I’m getting an error:

TypeError: DecisionTreeClassifier is not a constructor

The node modules looks like:
Screenshot from 2020-11-24 14-53-27

any ideas would be great, thanks!

const MLCart = require('ml-cart');
// or whatever you want to call it


// Use it
MLCart.DecisionTreeClassifier

Or this:

const DTClassifier = require('ml-cart').DecisionTreeClassifier

The ESModules import is you importing a specific named function called DecisionTreeClassifier, the syntax you’re trying for Common JS imports is for a default export.

1 Like

@DanCouper Thanks so much!