What is a good strategy for stopping a requireJS module from loading from information you won't know until run-time?
The scheme I came up with involves using a loader plug-in that checks some run-time attributes and checks the "protected" modules against their attribute lists, and if they're not supposed to load, doesn't call load() from inside the loader plug-in load() function. However, this results in a browser error, which in older versions of IE, cause actual script errors, which is not what I want/need (it's actually a time-out error because load() is never called).
Is there a way to say, "Yeah, I got that you wanted to load this, but, um, we don't want to, and that's not an error, so go about your business with the rest of your loading business." Or perhaps a better scheme to achieve what I want?
I solved this by doing load(null) and checking for null in the places where the module that could possibly not be loaded is referenced.
Related
Transpilation plugins like es6!, es!, and cs! are more complicated than simple plugins like text! because they return javascript modules that have their own dependencies.
Specifically, the code I've seen loads the specified file through XHR, transforms it, and then returns the result via a call like
onload.fromText("define(['foo', 'bar', ...");
That works fine for small test cases but throws a "Mismatched anonymous define() module" exception when running in my actual app. It's a race condition that happens when RequireJS is simultaneously processing a bunch of normal JS requires at the same time as evaluating a bunch of plugin requires.
Is this just a RequireJS bug, or is the plugin doing it wrong? Or, is it just not supported? Despite multiple transpilation plugin examples on the web, the RequireJS doc on that error says that
If you use the loader plugins or anonymous modules (modules that call define() with no string ID) but do not use the RequireJS optimizer to combine files together, this error can occur.
I've been toying with this all day to no avail so far. I've been using chartjs-node with no issues but I can't even load chartjs-chart-financial.
I've built the library and even used their pre-provided one (https://github.com/vmpowerio/chartjs-node), but whenever I require() the file, it throws errors such as:
Window is not defined
Chart.Ticks is undefined
These errors are on the loading of this file, not even the execution of the function.
I can't seem to figure out what's wrong and all my workarounds aren't getting anywhere. I feel like I'm missing something right in front of my face, too.
I am writing a script in SuiteScript 2.0 where I pass a function to a different module to use, in order to decouple functionality between the two. The functions of the modules seem to work fine together but when I call search.create on an ad-hoc saved search I got "Cannot find function _marshal in object [object Object]" error, I have no idea what this is. I tried passing in the scope using call and that had no affect but the shared functions between the modules are fine. Any help with this would be greatly appreciated. thanks
I also received this error using a search.create, but it was because I was passing in an object instead of a single value for the internal ID.
Apparently, the loading of multiple common modules like search etc, was causing the problem. By centralizing the access to the different modules seemed to have stopped the error. Also, side note, by getting rid of global objects like shared arrays between the modules seemed to make the code run quite a bit faster.
Every time I try to load my file i get the error "Module "Main" already loaded".
The file i am trying to load loads another module, the module loads by itself fine.
The file only loads that module and nothing else.
Can anyone tell me why it is giving me this error?
Thanks
This is a Hugs error, and honestly my first recommendation would be to switch to GHC. Is there a particular reason you're using Hugs?
However, if you don't want to or can't switch, this page says the following:
This error happens if you load two anonymous modules into (Win)Hugs. The solution is to name the modules concerned and to set up the appropriate import/export structures.
You can use this page as a guide for setting up the module names and import/export structures.
I'm currently trying to load a plugin assembly dynamically in a monotouch app.
To do this, I'm referencing the plugin dll in my app project, setting the limker to 'sdk only' and then i'm trying to call Assembly.Load(filename) within my app when the plugin is required.
This is the same approach that I've previously successfully used in monodroid. However currently, this is failing in monotouch with a FileLoadException.
Is this approach possible in monotouch? Is there a special file path you need to include? Or is this not supported in the aot environment?
Note: Obviously there are other ways I can achieve a similar effect - and I do have a backup plan... but this is my preferred route (if I can make it work)
Code like:
var a = Assembly.Load ("mscorlib.dll");
Assert.NotNull (a);
works fine with both the simulator and devices. However the parameter for Load is assemblyString which is not a filename (even if the exception thrown make you think it is).
Many other overloads exists (for Load) and other methods too (e.g. LoadFrom) but they might not all work inside MonoTouch (since some runtime support might be missing).
NOTE
Handling of mscorlib.dll is special (and works in more cases than other assembles, i.e. shortcuts). However the reflection-based methods seems to work as expected in more cases, e.g.:
string filename = System.IO.Path.GetFileName (GetType ().Assembly.Location);
Assembly assembly = Assembly.ReflectionOnlyLoadFrom (filename);
Assembly.Load (or any other way of loading code dynamically) is not supported in MonoTouch.
This is an iOS restriction - all the executable code has to be in the app (and it has to be native code, which is why we use AOT to generate native code at compile time).