question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blockly.JavaScript is undefined

See original GitHub issue

Expected Behavior

print JavaScript code from blocks

Actual Behavior

Uncaught TypeError: Cannot read property 'workspaceToCode' of undefined

ie. JavaScript property do not exists in Blockly instance

Steps to Reproduce

  1. git clone
  2. npm install
  3. run tests/vertical_playground.html
  4. press to JavaScript button

Operating System and Browser

Win10, Chrome 64

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
TheBrokenRailcommented, Feb 25, 2018

You need to import the JavaScript generator to have access to Blockly.Javascript

<script src="../javascript_compressed.js"></script>

This will not allow you to convert the blocks to JavaScript as generators are not being used for scratch-blocks.

1reaction
darkwavecommented, Mar 3, 2019

Blockly current version of javascript_compressed.js doesn’t work anymore because Blockly.Variables.allUsedVarModels is undefined in scratch-blocks but used in Google Blockly now.

Adding following code before attempting to generate Javascript code from blocks solve the issue:


if (!Blockly.Variables.allUsedVarModels) {
  Blockly.Variables.allUsedVarModels = function(a) {
    var b = a.getAllBlocks(!1);
    a = Object.create(null);
    for (var c = 0; c < b.length; c++) {
      var d = b[c].getVarModels();
      if (d)
      for (var e = 0; e < d.length; e++) {
        var f = d[e];
        f.getId() && (a[f.getId()] = f)
      }
    }
    b = [];
    for (var g in a)
    b.push(a[g]);
    return b
  }
};

Also It appears that Blockly.Variables.allUsedVariables is now deprecated in Google Blockly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blockly.javascript is undefined - Google Groups
In a react based blockly app am able to add blocks dynamically using: Blockly.JavaScript['some_block_type'] = function () {.... Problem arises ...
Read more >
javascript - blocky - property of undefined - Stack Overflow
I am trying to create a custom block in blockly but can't seems ... JavaScript['say_input'] = function(block) { var text_say_input = block.
Read more >
Generating and Running JavaScript | Blockly
Advanced methods for evaluating generated JavaScript code.
Read more >
How to use the blockly.JavaScript function in blockly - Snyk
To help you get started, we've selected a few blockly.JavaScript examples, based on popular ways it is used in public projects.
Read more >
blockly - npm
Blockly is a library for building visual programming editors.. Latest version: 9.2.0, last published: 14 days ago. Start using blockly in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found