Closed DaanVandenBosch closed 1 year ago
It is, and that’s on me... I need better browser testing on my side.
Immediate solution?: Try using 4.16
I don’t have time to fix today but tomorrow I should.
What steps can I take to replicate its failure?
Are you bringing it in through a script tag?
Does it fail when you try and solve a model or when you call something else?
Are you building it yourself or using the one prebuilt in the package?
On Sat, Oct 26, 2019 at 10:35 AM Daan Vanden Bosch notifications@github.com wrote:
I just upgraded from 0.4.5 to 0.4.20 and I get these errors:
./node_modules/javascript-lp-solver/src/External/lpsolve/main.js Module not found: Error: Can't resolve 'child_process' in 'C:\Users\Daan\code\phantasmal-world\node_modules\javascript-lp-solver\src\External\lpsolve' ./node_modules/javascript-lp-solver/src/External/lpsolve/main.js Module not found: Error: Can't resolve 'fs' in 'C:\Users\Daan\code\phantasmal-world\node_modules\javascript-lp-solver\src\External\lpsolve'
Is browser support no longer a feature?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JWally/jsLPSolver/issues/96?email_source=notifications&email_token=AAS6F53C4ZE2EAPECORLXB3QQRPTTA5CNFSM4JFNWXCKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HUROYVQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAS6F57ACKI54M2SNADORODQQRPTTANCNFSM4JFNWXCA .
We're using it in this project: https://github.com/DaanVandenBosch/phantasmal-world (first line of this file: https://github.com/DaanVandenBosch/phantasmal-world/blob/master/src/hunt_optimizer/stores/HuntOptimizerStore.ts).
We use the package from npmjs (through yarn). And we use webpack to load it as a module. It's actually webpack that throws the error (before we can even load the module) because it can't find "child-process" and "fs", which are node built-in modules. The errors seem to stem from this file: https://github.com/JWally/jsLPSolver/blob/master/src/External/lpsolve/main.js
And 0.4.17 is the most recent version available on npmjs that does work and it's the version we're using at the moment.
I built out a better "test-suite" to make sure the library works in the browser.
1.) node server.js 2.) Aim a browser @ http://localhost:9000/test/test.html
However, I'm not sure if this helps you since it looks like webpack is what throws a fit when trying to compile everything...
Just curious, can you change what webpack compiles?
Right now, it looks like you're using /src/main.js. What happens if you use /prod/solver.js?
What about this:
In your webpack config file, add the following:
const webpack = require('webpack'); //to access built-in plugins
module.exports = {
"mode": "development",
"plugins": [
new webpack.IgnorePlugin(/(fs|child_process)/),
]
}
On my side, I've moved the 'fs' requirement inside the function that calls it so its no longer globally exposed and shouldn't cause issues in the browser.
@DaanVandenBosch , does this solve your issue?
I've actually applied a patch to mitigate this:
--- "a/node_modules/javascript-lp-solver/src/main.js"
+++ "b/node_modules/javascript-lp-solver/src/main.js"
@@ -25,7 +25,7 @@ var Constraint = expressions.Constraint;
var Variable = expressions.Variable;
var Numeral = expressions.Numeral;
var Term = expressions.Term;
-var External = require("./External/main.js");
+var External = {};
// Place everything under the Solver Name Space
var Solver = function () {
I just upgraded from 0.4.5 to 0.4.20 and I get these errors using webpack:
Is browser support no longer a feature?
Edit: 0.4.17 does work in the browser.