If you use webpack for building your app, you can easily add and import Keras.js as a dependency:

yarn add keras-js
# or
npm install keras-js --save
import KerasJS from 'keras-js'

Webpack Config

The following must be included in your webpack configuration file:

node: {
  fs: 'empty'
}

Otherwise when building your app's webpack bundle, you may encounter the following error:

ERROR in ./node_modules/keras-js/lib/Model.js
Module not found: Error: Can't resolve 'fs' in '/usr/src/app/node_modules/keras-js/lib'

UglifyJS

If you use UglifyJS when building your bundle, it is important that the option compress be set to false. The default is true, so UglifyJS will drop unreferenced functions and variables (simple direct variable assignments do not count as references).

This is important, as a bundle built using the default options will not work!

For uglifyjs-webpack-plugin 1.0+ (which uses UglifyJS v3):

new UglifyJsPlugin({
  // ...
  uglifyOptions: { compress: { unused: false } }
})

For uglifyjs-webpack-plugin < 1.0:

new UglifyJsPlugin({
  // ...
  compress: { unused: false }
})