"Uncaught TypeError: global is undefined" when using custom Blockly modules with Parcel
See original GitHub issueDescribe the bug
When using custom Blockly modules with Parcel, I get the error Uncaught TypeError: global is undefined
.
To Reproduce
- I forked the blockly-samples repository, then
cd blockly-samples/examples/blockly-parcel
, andnpm install
; npm start
-> Parcel builds the app successfully, and the Blockly app on the local web server is working;- 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).
- Then I imported the local Python generator instead the built-in Python generator, and added the
google-closure-library
to requirements (to avoid agoog is not define error
) (74338a5). npm start
-> Parcel still builds the app successfully, but this time I get the errorUncaught TypeError: global is undefined
.
Expected behavior
Blockly Parcel app should work with a custom local generator.
Screenshots
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:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 =)
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 sinceBlockly.Python
is not written that way you can’t re-use any of theBlockly.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.