workarounds "window.require" method being overwritten by another script

6 views
Skip to first unread message

henrique matias

unread,
Apr 11, 2014, 11:28:29 AM4/11/14
to node-...@googlegroups.com
Hello Guys,

I'm using a builder script which overrides the "require" method on the window.

Unfortunately that brings a big issue, which is, i can't use "node-webkit"'s require function anymore.

Is that a comum issue? Is there a workaround for it?


thanks a lot

Marc Torruella

unread,
Apr 11, 2014, 11:34:20 AM4/11/14
to node-...@googlegroups.com

I would try to store the require funtion reference in a global variable before doing anything else and the use that new variable instead of require...

El dia 11/04/2014 17:28, "henrique matias" <hems....@gmail.com> va escriure:
--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

henrique matias

unread,
Apr 11, 2014, 11:45:57 AM4/11/14
to node-...@googlegroups.com
I did that, 

window.nw = window.require

<script src="my_script.js"></script>

But then, when using 

gui = window.nw "nw.gui"

inside my script, i get the following error:

[50943:0411/164407:INFO:CONSOLE(3967)] "Uncaught Error: Module not found: util", source: file:///blahblah/public/app.js (3967)

henrique matias

unread,
Apr 11, 2014, 12:00:13 PM4/11/14
to node-...@googlegroups.com
actually i found out that if i change the built script to don't export to window, everything works..

so from within my script, i can do

window.require = nw require
require = my require

henrique matias

unread,
Apr 11, 2014, 12:12:01 PM4/11/14
to node-...@googlegroups.com
the only side-effect is, now if i build my code using "split mode" which will build each file separately weird stuff will happen ( as in: will break ).

but well, my main issue is solved ( :

Marc Torruella

unread,
Apr 11, 2014, 5:38:43 PM4/11/14
to node-...@googlegroups.com
glad to hear, and thank you for sharing :-)
Reply all
Reply to author
Forward
0 new messages