[NPM] javascript-lp-solver

Hello I am struggling to use the javascript-lp-solver.

I have added the package to a collection using the NPM plugin.

However, when I try to reference it, it shows as empty.

Looking in the console, it seems to be importing the script, but the script ‘requires’ another script, which I think it cannot find. See the screenshot below, error on line 20, reading:

“Uncaught ReferenceError: require is not defined”

I’ve read online the browsers need an ‘import’ statement here instead?

Finally, in the documentation, there seems to be a way to do it via Node, Web and Webpack ( does weweb use webpack?) See documentation snippet below:

### Install:


(in Node)
npm install javascript-lp-solver --save

(in browser through CDN)
html
<script src="https://unpkg.com/javascript-lp-solver/prod/solver.js"></script>


(webpack)
javascript
const webpack = require('webpack'); //to access built-in plugins

module.exports = {
        "mode": "development",
        "plugins": [
            new webpack.IgnorePlugin(/(fs|child_process)/),
        ]
}

Im a bit lost on how to get this working and would love some help!

Thanks

this is a case where the library does bundle a umd version but not in the way unpkg expects it. You need to load the script (see the library docs) by yourself (there are a lot of ways to do it, I suggest using js actions in a workflow)

You can make a custom javascript step to embed the script tag described in the readme with https://weweb-embed.statechange.ai/

You would add this line from the README into the textarea into the text box:

<script src="https://unpkg.com/javascript-lp-solver/prod/solver.js"></script>

Thanks, got it working!

Fantastic video Ray, really dumbed it down for me, exactly what I needed :smile: