typescript requireJS hitting recursive load error - from a new call - requirejs

This only occurs in our application which is a ton of code and not something I can put up, nor something anyone would be willing to slog through. So all I can do is describe the error.
We are building our typescript with --amd and have a ton of recursive references between files. It all is working fine until I put this one call in a function:
var di = new moduleDocIterator.DocIterator(null);
With this, the initial load of the main .ts (.js actually) file gives me the null or undefined reference exception on setting up __extends at the top of the generated .js file.
Both the file this call is in and the file moduleDocIterator references have nothing static in them except a couple of strings. The generated .js creates the object for each class but nothing that looks like it is actually executing.
And none of this code is called at the time this happens. This is just the initial load of everything asked for via requireJS.
How do I figure out why it's unhappy?

Related

Loading JSON file not reflecting changes

I have a JSON file I use to store dialogue for a game. However, the changes I make to this JSON file are sometimes not reflected in my game even after hard reloads (I've been doing ctrl+shift+r or shift+F5 for this). I have made sure the changes to the JSON file are saved.
I have this.load.json('dialogue', 'assets/dialogue.json'); in preload(), and this.dialogue = this.cache.json.get('dialogue'); in create().
When I try copy+pasting the contents to a new different file (e.g. dialogue-2.json), and update my this.load.json() to reflect the new file name, the changes do get loaded.
The problem is that phaser doesn't automatic start the loading files, except in the preload function.
If you want to load files in other functions you need to call the start method of the LoadPlugin. Here the link to the official documentation.
The code should look something like this:
function create(){
// some code here ...
this.load.json(/* key and file...*/);
// start the loading of the enqueued files
this.load.start();
// some code here...
}
..., than the files should get loaded.
Update (copied form comments):
to check (and as a tempoary quickfix) if your problem, is a caching issue from the Webserver or browser or ..., you can load the file with a "dynamic" Url.
Just a load the file with a questionmark and random number added to the url, so that each call to the json uses aunique Url.
For Example like this:
this.load.json('dialogue', 'assets/dialogue.json?' + Math.random());
If this solves the problem, there is a caching problem. It could be in the browser, or simply caused by serviceworker or on the webserver.

The spine plugin for Phaser gives an error

I'm trying to upload the plugin to my project, tried all the methods, but nothing works. Returns an error
Uncaught TypeError: Cannot read properties of undefined (reading 'createSkeleton')
at initialize.set Skeleton (<anonymous>:1:290667)
at new initialize (<anonymous>:1:289262)
at Game Object Factory.spine (<anonymous>:1:54310)
at MainWindow.create (MainWindow.js?21c4:53:27)
at SceneManager.create (phaser.js?d4ef:89720:1)
at SceneManager.loadComplete (phaser.js?d4ef:89632:1)
at Loader Plug in.emit (phaser.js?d4ef:1908:1)
at Leaderplugin.loadComplete (phaser.js?d4ef:192810:1)
at Loader Plug in.file Process Complete (phaser.js?d4ef:192776:1)
at t.on Process Complete (<anonymous>:1:25378)
I work on a local server. Here is a code example of how I connect everything
I think it's the same problem I had. My spine JSON data were saved in an old format. You probably used DragonBones, which exports only version 3.3 spine data.
Here are the details someone remarked what's wrong with the file. You have three options: (A) change the file manually each time you export it, (B) use the python file the dude provides there, or (C) make a function to change the data structure accordingly after they are loaded and before the skeleton is added to scene. (This is the way I went.)

Log statements in Node Module not getting printed

I am a new to Node JS. I have included a module via npm install '<module_name>. It was built correctly and there was no errors. Now, I wanted to debug it, so I placed a few console.log('some text') in code blocks of the module to see if the code by passes that line. Anyway, none of the log statements were displayed.
I am wondering if I have to compile or something the modules after adding the log staements. Am I missing something here.
Your console.log statements are not being run, this could be caused by many things.
Assuming you have added the console.log statements to the module code in the node_modules directory of your app..
does the module have src and dist directories and you have not edited the code that is actually being run? (this relates to needing to recompile, but editing the actual code that the module is running will be quicker and easier)
if this is in a server or long running script it will need to be restarted to load the changes
is this in a browser which might be caching the code (turn off browser cache)
is the code where you added the log statements actually being hit?
I would make sure I had a console.log statement in a part of the code guaranteed to be hit, just as a sanity check.
For anyone coming here in the future, try console.error instead of console.log. For some decided reason or another, log was being overriding by the library I was monkey fixing. Took me way too long to find the culprit.

How to copy files as templates, injecting values to them, to a different folder?

I used this library, mem-fs-editor (https://github.com/sboudrias/mem-fs-editor), in a Yeoman generator a few weeks ago. It worked nicely, but now I tried to use it again in a different scope and I couldn't do anything. Obs: I used it because this is the library Yeoman provides to handle the file system.
In Yeoman Generators we can copy files from a template folder, passing values to inject in the code, to a different folder. And that's precisely what I need, but I can't use Yeoman this time.
I tried the same code I used in my Yo Generator, but it don't work. So I'm not sure how mem-fs works. No errors are thrown and even the code provided by the author of the project don't work to me.
I tried this (and some other things with copyTpl) with no success
var memFs = require('mem-fs');
var editor = require('mem-fs-editor');
var store = memFs.create();
var fs = editor.create(store);
console.log(fs.write('./somefile.js', 'var a = 1;'));
Anyone knows how it works or what else I can do to make this happen?
mem-fs-editor author here.
mem-fs stands for memory file-system. All the files you creates are stored in memory and won't get written to disk until you call:
editor.commit(callback);
Yeoman does that automatically for you. It is this way with Yeoman to collide every file changes together and then being able to only prompt for file conflicts once (rather than everytime a single file is being written to).

Node.js - Sharing variables between different files

I am new here and pretty new to Node.js. I got Express working fine, connecting to MySQL (database) is going fine, and socket io is working fine.
But I decided to split many of these features up in separated files. To keep my main JS file nice and clean. I made it possible to get variables from other js files back to my main.js script. Either using exports, or global. I find global working easier since most of them are functions. It's all working fine to this point.
But now the issue that I am having. I'm loading 3 js files in my main.js file. I am requiring the first js file, I call the function that is in that js file and store the result in a variable. That's going fine. But now the second js file is suppose to use or grab this variable, and that isn't working.
My question is, how do I make that work?
It is a matter of your design.
You should use module.exports to return a variable from a file.
Example:
file1.js
function someFunction() {return true;}
module.exports = someFunction();
main.js
console.log(require('./file.js')); // true
So, if the second file depends on the variable from the first file, you may also require the file1.js in the second one.
Or, export a function that accept one parameter in the second file. The main file should then use the variable from first file to call the function.

Resources