Sencha cmd, closure compiler error: how to locate the offending code - javascript

When running Sencha cmd 6.5, and I get the following error:
[ERR] C2001: Closure Compiler Error (Parse error. undefined label "f") -- compression-input:1:4095
How can I locate the code at compression-input:1:4095 ?
This happens when I include a custom javascript file in app.json using:
"js": [
{
"path": "app.js",
"bundle": true
},{
"path": "custom.js",
"includeInBundle": true
}
],
The error disapears when I remove the reference to custom.js in app.json.
If I interpret the error correctly, it means that closure compiler finds an error on line 1, character 4095 of the compression-input. But the first line of custom.js is not such long.
How can I locate the offending code ?
And by the way, what is an undefined label in closure compiler ?

I had the same issue a year ago, and I was told you cannot locate it from the error message.
Assuming that you have already tried to open your uncompiled project directly in the browser, and not getting a syntax error, there's not much you can do except narrowing it down further by splitting the custom.js content in two parts and check these independently.
In my case it was Ext.define where should have been Ext.create, and the syntax error is thrown because usage of Ext.define is rewritten into other commands during generation of the compression-input. Maybe if you look for this specifically, you can find it.

Related

Designate additional alias names for eslint consistent-this rule?

I recently started using the eslint module to help clean-up some JavaScript files. The following error is being reported when I lint one of my files:
127:17 error Unexpected alias 'me' for 'this' consistent-this
After checking the documentation, I understand the error is being reported because my code is assigning the value of this to a variable named me instead of that.
What is the proper way to configure my project's .eslintrc.json to make it so the following line of code is not reported as an error: var me = this;?
The rule should be like this in your .eslintrc
{
"rules" : {
"consistent-this": ["error", "me"]
}
}

ESLINT errors ( Error '$' is not defined)

I have Brackets installed, and i getting ESLINT error, as far as i know i dont have ESLINT installed
That is the first time i get this error, my question is, how do i install ESLINT and configure it that i don't receive the errors. ( The JavaScript code is copied from CODEPEN so it should be ok)
The main problem is ESLINt, i tried with other JS plugins and get the same error, as i said its the first time im getting this error.
You need to configure it to allow globals:
https://eslint.org/docs/user-guide/configuring#specifying-globals
Either comment on top of the file
/* global $ */
or in the config
You need to add the '$' to the globals object inside your .eslintrc file.
Like so:
"eslintConfig": {
"globals": {
"$": true
}
}

How do I debug Uglify parse errors?

I'm uglifying a JS file and just started getting
DEBUG: { message: 'Unexpected token: name (a)',
line: 1,
col: 17726,
pos: 17726
What are the debugging steps I need to follow to track this down?
Needless to say, I've tried the obvious stuff like searching for "name" and "(a)", neither of which appear in the file. It would also be helpful to see what "line:1 col: 17726" are referring to since my input file is beautiful JS.
Turns out the problem was the final line of one of the files didn't end with a CR. Thus, it and the first line on the following file were being concatenated into a single line.

Cannot start cocos after adding a new file

I have a bug where I'm met with the error: "Uncaught TypeError: Cannot read property 'style' of null" When running the command cocos run -p web. This results in not being able to start my app.
I seem to get this error when I add a new js file to my source folder. I've solved it previously by restarting my terminal, which seemed to do the trick. However, now I am unable to run my app in the browser because of this error.
The full error log can be seen in the below image:
It seems like the canvas element in CCBoot.js is null due to something not loading correctly. How can I go about solving this problem?
Eventually solved this after around 4 hours of debugging... The solution was painfully trivial, but the warning messages cocos2d-x was producing were extremely unuseful.
The problem stemmed from not being able to parse the project.json file correctly. When I added my new file to the jsList array in project.json, I added it like this:
{
"project_type": "javascript",
"debugMode" : 1,
"showFPS" : true,
"frameRate" : 60,
"noCache" : false,
"id" : "gameCanvas",
"renderMode" : 0,
"engineDir":"frameworks/cocos2d-html5",
"modules" : ["cocos2d"],
"jsList" : [
"src/resource.js",
"src/app.js",
"src/newFile.js",
],
}
The comma after src/newFile.js and the jsList array messed up the file, causing all the problems. Therefore, to fix the project.json file I changed it to:
"jsList" : [
"src/resource.js",
"src/app.js",
"src/newFile.js"
]
To conclude, if you are also experiencing problems like this, check the formatting of your project.json file and make sure everything is formatted correctly - if you're unsure how to format it start a new project and use a fresh project.json file as a guide!

Cocos2d-js EditBox Undefined

I am having an issue with Cocos2d-js, where it doesn't seem to think that cc.EditBox exists. I create a new project and try to delcare:
var box = cc.EditBox.create(...)
And I get this error in my browser console:
Uncaught TypeError: Cannot read property 'create' of undefined
I cannot figure out why this would be the case. Within the project directory I can even see that frameworks/cocos2d-html5/extensions/editbox exists and contains the files CCdomNode.js and CCEditBox.js.
Does anyone have an explanation and/or solution?
It's a common error, the problem is that EditBox is an optional module.
You need to add "editbox" to the modules list in your game's project.json file, and then cc.EditBox will be defined.
Like this
"modules": [
"cocos2d",
"cocostudio",
"editbox"
],

Resources