JSON source mapping breaks the parser in Webstorm debug process - javascript

My problem is exactly like this one:
https://github.com/mrdoob/three.js/issues/4639
While debugging my js app in WebStorm, every JSON from XMLHttpRequest response is annotated with:
//# sourceURL=http://localhost:63342/JSON_URL_here
This doesn't happen while debugging in Chrome with Jetbrains plugin deactivated, so I guess it's a fair bet that WebStorm is performing the annotation.
The problem is, the JSON file can't be parsed, throwing the following error:
Uncaught SyntaxError: Unexpected token /
Is it possible to solve this issue, other than changing the THREE source code and manually removing the problematic line?

sourceURL appended to any JS file loaded via XHR (jquery load script for example). Otherwise it is impossible to set breakpoint.
You should not use ".js" file extension for JSON files, please use ".json" instead. Is it possible in your case?

Related

How do I solve the ReferenceError in my API calls from my UI?

I have done a microsoft tutorial called Web API with Javascript
I now have a UI made with Javascript and HTML which looks like this:
How do I use the UI? I keep getting a Reference Error. Is there a specific syntax I am supposed to follow when I add and edit something via APIs?
In the future, please copy and paste error messages into your question. I would normally copy and paste the error message in my answer, but I don't want to type it all out :)
The errors (red) mean that you're trying to use JavaScript that is not defined yet. The warnings (yellow) are the reason why.
The second warning says that it could not load the JavaScript. That explains the errors. The first warning might be the reason why. It's saying that the MIME type is empty, when it should be application/javascript.
But you said in the comments that the site.js file is empty when you try to access it directly. Did you save all the JavaScript in step 4 of that tutorial to site.js?
And what are you using as a web server? IIS Express?

Bundling and minification - when enabled scripts don't work

Trying to apply bundling to scripts, which worked fine when were located at pages in old way (manually).
This is bundles registration:
Bundle sbundle = new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/menu-correction.js",
"~/Scripts/validation-rules.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery.validate*");
bundles.Add(sbundle);
bundles.Add(new ScriptBundle("~/bundles/session").Include(
"~/Scripts/jquery.plugin.js",
"~/Scripts/jquery.countdown.js",
"~/Scripts/session-management.js"));
//others
Then in Layout page call:
#Scripts.Render("~/bundles/jqueryval")
#Scripts.Render("~/bundles/session")
But when minification is become enabled, i got this errors in chrome console:
Uncaught SyntaxError: Unexpected identifier jqueryval:1
Uncaught SyntaxError: Unexpected identifier session:1
Also i can see my scripts in tab page "Sources" of chrome developer tools - they are minificated successfully. Spent enough time trying to fix this. What can be a reason of this mistake?
Thanks in advance.
I provided insufficient information: there is some logic in Application_PostRequestHandlerExecute method which wrotes some tags directly to response stream (is needed for js). I noticed that tags which were written directly in response stream with bundling is being written actually in the end of minificated js file.Thus, syntax is broken and js file doesn't work (Without bundling my approach works fine).
Solution: transferred my logic from Application_PostRequestHandlerExecute to Application_AuthorizeRequest method, where it should was located initially.
UPDATE
Well, tag generating logic was entirely removed from Application_PostRequestHandlerExecute method, cause only now i understand that this is absolutely wrong idea.

JavaScript: Unexpected End of Input... because it's only loading part of the file?

Strange error here: I have a page that's referencing several JavaScript files. Occasionally, the browser will complain of:
Uncaught SyntaxError: Unexpected end of input
However, it doesn't appear to be due to a missing parent, or malformed JSON. Part of the JavaScript file will load, but the program will just stop loading the rest of the file. Example: half of the file will load, with the other half missing.
Most of the time, the files load and everything works. Any idea why I would occasionally be getting this error, rather than every time (as expected with a missing paren or something similar)? Other things I can check?
EDIT:
This is a Rails project (Rails version 3.2).
The JS files are standalone, and are kept in the pub directory for dev. In other words, they are NOT included in the asset pipeline.
There must be braces not closed properly.The file stops loading whenever the error is encountered and leaves the rest part unloaded as because of error.
You can check this example here

GWAN is modifying jquery.min.js to error

I am doing an experimental HTML template wich comes with jquery.min.js file - one of the most popular javascript libraries.
When I load the template from my local hard drive it works fine.
When I upload it and load it from server (GWAN) I get error (I think is not the only one) in Chrome looks like this:
Uncaught SyntaxError: Unexpected token { jquery.min.js:3
I inspected a bit and realized there is a
function $
which was turned into
function$
by GWan. The space removed is causing an error in Chrome, Firefox and Safari. I haven't tested other browsers but my IDE also reports a syntax error in the downloaded from GWAN version of the JS file.
I have also tried uploading the files to another server (Apache) and no problem there. The js file was not modified...
Any clues on how to get over this? I suppose there is a bug in javascript on-the-fly optimization of GWan?
Thanks.
It's a known issue and it will be fixed in next release (soon)
You'll be able to disable minifying directly from a init.c script in G-WAN v4.10+, this way:
u8 *www_mini = (u8*)get_env(argv, USE_MINIFYING);
if(www_mini)
{
*www_mini = 0;
puts("> disable minifying");
}
You just have to wait for few days for the new v5 release.

Symfony 2 - Assetic JavaScript compression causing errors

I'm trying to put a Symfony 2 app in production mode. It all runs fine except for the fact that the compressed single JavaScript file causes errors and makes the site unable to render correctly. I found this through the debug console on the browser:
Uncaught TypeError: undefined is not a function
Uncaught TypeError: Object [object Object] has no method 'treeview'
The first error refers to jQuery plug-ins
The treeview refers to a plugin for jQuery which renders a tree like directory structure.
On the other hand, it all runs fine on dev mode cause it doesn't do the compression and it just includes every file one by one. Can someone help me on this one?
I've found a solution to this, it appears the issue is related to missing semi-colons.
When something is the last statement in a js file a semi-colon isn't required however assetic just joins the files together and only adds a new line.
Check the file which is being included just before the broken plugin javascript and make sure it ends with a semicolon.

Categories