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.

"Uncaught TypeError: global is undefined" when using custom Blockly modules with Parcel

See original GitHub issue

Describe the bug

When using custom Blockly modules with Parcel, I get the error Uncaught TypeError: global is undefined.

To Reproduce

  1. I forked the blockly-samples repository, then cd blockly-samples/examples/blockly-parcel, and npm install;
  2. npm start -> Parcel builds the app successfully, and the Blockly app on the local web server is working;
  3. then I added the Python generator locally, based on the Python generator in the blockly repository, as a temporary step to create and use my own generator (397de71).
  4. Then I imported the local Python generator instead the built-in Python generator, and added the google-closure-library to requirements (to avoid a goog is not define error) (74338a5).
  5. npm start -> Parcel still builds the app successfully, but this time I get the error Uncaught TypeError: global is undefined.

Expected behavior

Blockly Parcel app should work with a custom local generator.

Screenshots

image

Desktop:

  • OS: Debian
  • Browser: Firefox
  • Version: 90

Stack Traces

Uncaught TypeError: global is undefined
    ["4zfCE"]< nodejs.js:49
    newRequire generator.54de7a8f.js:71
    localRequire generator.54de7a8f.js:83
    ["2PZRm"]< generator.js:11
    newRequire generator.54de7a8f.js:71
    <anonymous> generator.54de7a8f.js:120
    <anonymous> generator.54de7a8f.js:143
nodejs.js:49
    ["4zfCE"]< nodejs.js:49
    newRequire generator.54de7a8f.js:71
    localRequire generator.54de7a8f.js:83
    ["2PZRm"]< generator.js:11
    newRequire generator.54de7a8f.js:71
    <anonyme> generator.54de7a8f.js:120
    <anonyme> generator.54de7a8f.js:143
    InnerModuleEvaluation self-hosted:2381
    evaluation self-hosted:2332

If I follow the stacktrace, this error seems to be trigered by this line in the google closure library.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
BeksOmegacommented, Jul 26, 2021

Hi @2torus , have you run into any issues like this? Or have tips for where to start looking for a fix? Just sending a ping because you have more experience with Parcel than any of the people on the core team hehe.

Also thanks for filing this issue @roipoussiere =)

0reactions
2toruscommented, Jul 30, 2021

There is a more fundamental issue here. You are trying to arrange things the way closure library works and it’s not compatible with parcel. Closure library is sticking attributes into global or semi-global objects like Blockly. It’s very brittle and frowned upon in modern software development. While you can still make it work with parcel, you don’t need to.

A proper way to do things is to subclass Blockly.Generator class and add block definitions as methods. I’m doing it with my project. The bad news is since Blockly.Python is not written that way you can’t re-use any of the Blockly.Python code without rewriting most of it properly. I saw that you opened #830 for this but that’s the gist of the idea without doing the actual work.

Replace goog.require with import and goog.provide with export.

Ok, so I tried this on my fork (5d66898), could you quickly check in the diff if the modifications on the imports and exports seem good for you?

But anyway, I get the same error (Uncaught TypeError: global is undefined), because goog is still used by the blockly dependency.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Uncaught TypeError: global is undefined" when using custom ...
Describe the bug When using custom Blockly modules with Parcel, I get the error Uncaught TypeError: global is undefined.
Read more >
THREE.js TypeError: 'global' is undefined in Firefox
So I tried to include threejs as a drop-in script into my code. No webpack, no browserify, no requirejs. Just a simple gulp/browsersync...
Read more >
ember app - OSCHINA - 中文开源技术交流社区
It works by spinning up a local FastBoot server using ember-cli-fastboot, and then runs your Mocha-based end-to-end tests to assert that your app...
Read more >
blockly-samples - githubmemory
Move workspace comments into a plugin · "Uncaught TypeError: global is undefined" when using custom Blockly modules with Parcel.
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