Cannot set properties of undefined (setting 'reward_function')

406 views
Skip to first unread message

Srijan Srivastava

unread,
Mar 28, 2023, 10:44:29 AM3/28/23
to Blockly
I am using vite+react for my project. Since there were new features to be implemented, I decided to move my Blockly workspace to react as it will be easier to implement those features in react. My code was working fine in vanilla JS and HTML, however, when I used react-blockly, I got the following error: Cannot set properties of undefined (setting 'reward_function') in the console. Does any body know why this is happening or how I can solve it?
Screenshot 2023-03-28 at 10.38.19 PM.png This is my folder structure
Screenshot 2023-03-28 at 10.39.12 PM.png This is my package.json
Screenshot 2023-03-28 at 10.39.55 PM.png This is my custom block file.
Screenshot 2023-03-28 at 10.40.43 PM.png My imports in App.js
I do not have this block on the toolbox, but pre-loaded on the workspace from the XML.
Screenshot 2023-03-28 at 10.43.05 PM.png This is the error on the developer tools.
Any idea on how to fix this?
PS: I ran the example given on react-blockly's github and it gave me the same error.
Thank you in adcance.

Maribeth Bottorff

unread,
Mar 28, 2023, 11:06:20 AM3/28/23
to Blockly
Hello,

What version of Blockly are you using? If using a recent version (I believe 9+) then generator imports have changed. You can find the documentation here. As a side note, you probably need a direct dependency on blockly and to use `import * as Blockly from 'blockly';` but neither of those are likely to be causing this problem.

If you have additional problems after fixing that, please reply, but do note that we on the core team are not particularly familiar with react-blockly; we'll still do our best to help though!

Maribeth

Srijan Srivastava

unread,
Mar 28, 2023, 11:42:20 AM3/28/23
to Blockly
Hello,

Thank you, Maribeth, for your reply.
I realised that this error only occurs when JS thinks that we are accessing something which is not defined (yet), but it is the crazy world of JS. So, I divided the files: one with block configurations and one with python generators. I called the block configurations first and then the generator. So, now my workspace is loading, and the blocks have no error. 
Thank you for recommending the imports. I have changed the code accordingly.
So, now my folder structure is as follows:
Screenshot 2023-03-28 at 11.38.10 PM.png
Also, here is an example snippet from the generators:
Screenshot 2023-03-28 at 11.39.00 PM.png
Updated imports:
Screenshot 2023-03-28 at 11.39.42 PM.png
Workspace working perfectly:
Screenshot 2023-03-28 at 11.40.16 PM.png
Thank you very much for your help.

Best,
Srijan

Maribeth Bottorff

unread,
Mar 29, 2023, 12:51:57 PM3/29/23
to Blockly
Great, glad you got it working!

Maribeth

Reply all
Reply to author
Forward
0 new messages