Error: multipleDefine

Just starting out? Need help? Post your questions and find answers here.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Error: multipleDefine

Post by skinkairewalker »

hello everyone !
I'm trying to load 2 .js scripts, but the error occurs:

Code: Select all

Error: multipleDefine
    at l (dojo.js:2)
    at Ja (dojo.js:24)
    at dojo.js:25
    at a (dojo.js:2)
    at Xa (dojo.js:25)
    at s (dojo.js:22)
    at HTMLScriptElement.<anonymous> (dojo.js:27)
screenshot : https://prnt.sc/13cqvf8


sb code :
( try 1 )

Code: Select all

Procedure InitApp(URL$, Success)
  ! $("<link rel='stylesheet' type='text/css'>").attr("href", "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css").appendTo("head");
  ! require(["https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"], function() {
  Main()
  ! });
EndProcedure

! require(["http://localhost/inodes/ws.js"], function(Q) {
  LoadScript("http://localhost/inodes/reconnecting-ws.js",@InitApp())
! });

( try 2 )

Code: Select all

Procedure InitApp(URL$, Success)
  ! $("<link rel='stylesheet' type='text/css'>").attr("href", "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css").appendTo("head");
  ! require(["https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"], function() {
  Main()
  ! });
EndProcedure

Procedure reconnect_ws(URL$, Success)
  LoadScript("http://localhost/inodes/ws.js",@InitApp(),#PB_Script_JavaScript)
EndProcedure

LoadScript("http://localhost/inodes/reconnecting-ws.js",@reconnect_ws(),#PB_Script_JavaScript)

is there anything i can do to solve this and load the scripts?
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Error: multipleDefine

Post by the.weavster »

Hi skinkairewalker,

Is there a reason you're mixing together LoadScript() and require()?
See if this works for you:

Code: Select all

Procedure Main()
  Debug "All good!"
EndProcedure

Procedure ExternalLoaded(URL$, Success)
  Static nLoaded
  If Success
    nLoaded + 1
    If nLoaded = 2 ; the number of files to import
      Main()
    EndIf
  Else
    Debug "Failed to load external: " + URL$
  EndIf
EndProcedure

LoadScript("https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css", @ExternalLoaded(), #PB_Script_CSS)
LoadScript("https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js", @ExternalLoaded(), #PB_Script_JavaScript)
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: Error: multipleDefine

Post by skinkairewalker »

it worked 100%, thanks the.weavster :D


but I came across a problem ...

I'm trying to use reconnecting-websocket.js ( https://github.com/joewalnes/reconnecting-websocket ) to use websocket functions, but its procedures are not being loaded ...

screenshot : https://prnt.sc/13d36to

the file "ws.js" it loads functions of "reconnecting-ws.js", do you know of any way to solve this?
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Error: multipleDefine

Post by the.weavster »

It looks like the problem might be that reconnecting-websocket detects that RequireJS has been loaded and so expects you to do something with that ...

Code: Select all

(function (global, factory) {
    if (typeof define === 'function' && define.amd) {
        define([], factory); // <- this is the branch it takes
    } else if (typeof module !== 'undefined' && module.exports){
        module.exports = factory();
    } else {
        global.ReconnectingWebSocket = factory(); // <- I think we want this
    }
})(this, function () { ...
So maybe my suggesting you use LoadScript() ( which I believe is based on jQuery $.ajax ) moved you further away from the solution rather than closer.
I don't know anything about requirejs so I'm afraid I'm out of my depth here.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: Error: multipleDefine

Post by skinkairewalker »

i am trying to using raw html with this code :

works fine screenshot > https://prnt.sc/13erd32

Code: Select all

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
        <title>teste</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.js"></script>
        <script src="/reconnecting-websocket.js"></script> <!-- loading directly -->
    </head>
    <body>
     </body>
</html>
works fine ( screenshot ) > https://prnt.sc/13er7mv

what are we doing wrong in spiderbasic ??

example source html ( https://drive.google.com/file/d/176yguT ... sp=sharing )
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Error: multipleDefine

Post by the.weavster »

Code: Select all

(function (global, factory) {
    if (typeof define === 'function' && define.amd) {
        define([], factory); // <- this is the branch it takes
    } else if (typeof module !== 'undefined' && module.exports){
        module.exports = factory();
    } else {
        global.ReconnectingWebSocket = factory(); // <- I think we want this
    }
})(this, function () { ...
A direct import in HTML will travel down the } else { branch of the above code (which is from the uncompressed version of what we're trying to import) so ReconnectingWebSocket is added to the global namespace. I think the problem arises as SpiderBasic has RequireJS somewhere under the hood which results in a different path through that function.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: Error: multipleDefine

Post by skinkairewalker »

will it remove or leave itself just

Code: Select all

global.ReconnectingWebSocket = factory ();
would solve?
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: Error: multipleDefine

Post by skinkairewalker »

works fine !!!!
thanks very much !!!!!
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Error: multipleDefine

Post by the.weavster »

How about this?

Code: Select all

Procedure Main()
  Debug "All good!"
  ws = #Null
  EnableJS
  v_ws = new window.ReconnectingWebSocket('');
  DisableJS
EndProcedure

Global nLoaded
Global nImports = 2

Procedure RequireScript(url.s, objName.s)
  EnableJS
  require([v_url], function(obj) {
    window[v_objname] = obj;
    v_nloaded++;
    if (v_nloaded == v_nimports) {
      f_main();
    }
  });
  DisableJS
EndProcedure

Procedure ExternalLoaded(URL$, Success)
  ;Static nLoaded
  If Success
    nLoaded + 1
    If nLoaded = nImports ; the number of files to import
      Main()
    EndIf
  Else
    Debug "Failed to load external: " + URL$
  EndIf
EndProcedure

LoadScript("https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css", @ExternalLoaded(), #PB_Script_CSS)
;LoadScript("https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js", @ExternalLoaded(), #PB_Script_JavaScript)
RequireScript("http://localhost/reconnecting-websocket.min.js", "ReconnectingWebSocket")
*Change the RequireScript() URL for your local setup

I'd be interested to know if it works.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: Error: multipleDefine

Post by skinkairewalker »

wow , awesome !!
but show this error when i run :

Code: Select all

Uncaught SyntaxError: Unexpected token '{'
how can i fix it ??
screenshot :
1 : https://prnt.sc/13f076o
2 : https://prnt.sc/13f09jy
Post Reply