jvail / glpk.js

GLPK for browser & node
GNU General Public License v3.0
106 stars 19 forks source link

"Uncaught ReferenceError: glpk is not defined" even after local loading #44

Open lbreal opened 3 months ago

lbreal commented 3 months ago

Hello,

I am facing a problem with GLPK.js. Even after downloading the glpk.min.js file and including it locally in my project, I keep getting the error "Uncaught ReferenceError: glpk is not defined".

My HTML code is as follows: <<!DOCTYPE html>

jvail commented 3 months ago

Hi,

here is a minimal example: https://github.com/jvail/glpk.js/blob/master/examples/lp.html If you adjust your import/script then it should work out of the box.

lbreal commented 3 months ago

Thanks for answering!

I'm still encountering difficulties using GLPK.js in my local development environment, even after trying different approaches. Here are the issues I'm facing:

Approach 1: Local File Import ( import GLPK from '../dist/index.js';) I'm unable to import GLPK.js as a module from a local file.

The error in console is: Access to script at 'file:///C:/Users/luiza/Documents/Documentos/PO/jogos/meu_jogo/glpk.min.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

Approach 2: CDN Import ( import GLPK from 'https://cdn.jsdelivr.net/npm/glpk.js@4.0.2/dist/glpk.min.js';)

When I try to import GLPK.js as a module from a CDN, I get a different error: Uncaught SyntaxError: The requested module 'https://cdn.jsdelivr.net/npm/glpk.js@4.0.2/dist/glpk.min.js' does not provide an export named 'default' (at teste.html:6:16)

The code used is the following:

<!DOCTYPE html>

Optimal Transportation Problem with GLPK.js

Optimal Transportation Problem with GLPK.js


    


            
jvail commented 3 months ago

The error in console is: Access to script at 'file:///C:/Users/luiza/Documents/Documentos/PO/jogos/meu_jogo/glpk.min.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

Yes, that is normal. If you want to develop locally I propose to use serve. That is what I do as well:

  1. Clone this repo
  2. Create your html/js files somewhere in the repo folder
  3. Run npx serve
  4. Navigate to your file in the browser e.g. http://localhost:3000/examples/lp