google / blockly-games

Games for tomorrow's programmers.
https://blockly.games/
Apache License 2.0
1.29k stars 605 forks source link

build error: variables undeclared #56

Closed elenaaralla closed 7 years ago

elenaaralla commented 7 years ago

Hi, I'm trying to compile blockly-games on Mac OSx Sierra 10.12.2

I was able to git clone and make deps, but when I run make maze-en (as an example) I get the following errors and warnings

any suggestion? thank you in advance Elena

=========================

third-party/build/closurebuilder.py: Compiling with the following command: java -client -jar third-party/closure-compiler.jar --flagfile /var/folders/86/1ltscfs5125g7q30mv875t_40000gn/T/tmpFRkQ9j
appengine/maze/js/maze.js:409: WARNING - Redeclared variable: tile
      var tile = document.createElementNS(Blockly.SVG_NS, 'image');
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

appengine/maze/js/maze.js:1389: WARNING - Redeclared variable: x
  for (var x = 0, path; path = paths[x]; x++) {
           ^^^^^

appengine/third-party/blockly/core/block.js:1017: WARNING - Redeclared variable: i
    for (var i = 0; i < extensionNames.length; ++i) {
             ^^^^^

appengine/third-party/blockly/core/extensions.js:58: WARNING - Bad type annotation. missing opening ( See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information.
 * @param {function} initFn The function to initialize an extended block.
                   ^

appengine/third-party/blockly/core/trashcan.js:185: WARNING - Redeclared variable: clip
  var clip = Blockly.utils.createSvgElement('clipPath',
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

appengine/third-party/blockly/core/utils.js:200: WARNING - Redeclared variable: scale
    var scale = Blockly.utils.getScale_(element);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

appengine/third-party/blockly/core/xml.js:357: WARNING - Redeclared variable: bbox
      var bbox = workspace.getBlocksBoundingBox();
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

appengine/third-party/blockly/core/zoom_controls.js:135: WARNING - Redeclared variable: clip
  var clip = Blockly.utils.createSvgElement('clipPath',
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

appengine/third-party/blockly/core/zoom_controls.js:151: WARNING - Redeclared variable: clip
  var clip = Blockly.utils.createSvgElement('clipPath',
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

appengine/third-party/blockly/generators/javascript.js:243: WARNING - Redeclared variable: comment
          var comment = Blockly.JavaScript.allNestedComments(childBlock);
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

appengine/js/lib-dialogs.js:374: ERROR - variable prettyPrintOne is undeclared
    if (typeof prettyPrintOne == 'function') {
               ^^^^^^^^^^^^^^

appengine/js/lib-interface.js:50: ERROR - variable BlocklyStorage is undeclared
    BlocklyStorage['HTTPREQUEST_ERROR'] =
    ^^^^^^^^^^^^^^

2 error(s), 10 warning(s)
Traceback (most recent call last):
  File "third-party/build/closurebuilder.py", line 293, in <module>
    main()
  File "third-party/build/closurebuilder.py", line 282, in main
    compiler_flags=options.compiler_flags)
  File "/Users/elena/blockly-games/third-party/build/jscompiler.py", line 159, in Compile
    raise JsCompilerError('JavaScript compilation failed.')
jscompiler.JsCompilerError: JavaScript compilation failed.
NeilFraser commented 7 years ago

FYI, neither of those errors are actual errors, I recognize both of those variables as coming from external (and optional) components. So the issue here is how to suppress these from being reported as errors.

elenaaralla commented 7 years ago

Hi thank you for the light-fast answer! I supposed that they are defined somewhere...but I was wondering if I missed something

NeilFraser commented 7 years ago

Both are defined in files that Closure Compiler can't see. The proper way to fix this would be to create externs for them. Try editing this file: https://github.com/google/blockly-games/blob/master/externs/interpreter-externs.js And add the following at the end:

var BlocklyStorage = {};
BlocklyStorage.backupOnUnload = function() {};
BlocklyStorage.restoreBlocks = function() {};
BlocklyStorage.link = function() {};
BlocklyStorage.retrieveXml = function(key) {};
BlocklyStorage.alert = function(message) {};
var prettyPrintOne = function(code, lang) {};
elenaaralla commented 7 years ago

Hi the changes you suggested fixed the errors and I was able to build maze-en There are still a lot of warnings (844!), maybe related to the error I get when I click on the pegman-button in the top right corner (TypeError: cd.jt is not a function. (In 'cd.jt(a,"buttonHover")', 'cd.jt' is undefined)

if I run maze in debug mode (using uncompressed file), the error is:

TypeError: Blockly.addClass is not a function. (In 'Blockly.addClass(button, 'buttonHover')', 'Blockly.addClass_' is undefined)

any clues?

build_log.txt

sandysaahil commented 7 years ago

Thanks NeilFraser, I did what you advised. Now I am getting lot of warnings but no error, but when I hit the url to pong-duck, I get a blank page. No console error. Any pointers?

hariscybersquare commented 7 years ago

The same error came for me (Blockly.addClass_ is not a function). I fixed it making the following change.

The line numbers in maze.js were 819 and 843. It had

Blockly.addClass_(button, 'buttonHover');

Blockly.removeClass_(document.getElementById('pegmanButton'), 'buttonHover');

I changed this to

Blockly.utils.addClass(button, 'buttonHover');

Blockly.utils.removeClass(document.getElementById('pegmanButton'), 'buttonHover');

I found this by looking at the code of utils.js under the third-party/blockly/core/utils.js.

screen shot 2017-07-14 at 4 16 43 am

NeilFraser commented 7 years ago

Several dependencies (including Blockly) changed over time, breaking the build. Blockly Games has been updated so that everything builds properly now.