Buffer is undefined in electron
See original GitHub issueIf I compile a .jsc file inside an electron process with bytenode.compileFile(‘./test.js’, ‘./test.jsc’); and that file contains references to node-js’s Buffer object. It is undefined.
So a “new Buffer(1);” gives a TypeError: undefined is not a constructor
exception. And this exception only occurs when requiring the .jsc file of course. The .js file works fine.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12
Top Results From Across the Web
Buffer is undefined in electron · Issue #10 · bytenode ... - GitHub
If I compile a .jsc file inside an electron process with bytenode.compileFile('./test.js', './test.jsc'); and that file contains references ...
Read more >Uncaught ReferenceError: Buffer is not defined - Stack Overflow
Answering my own question. Two things helped to resolve the issue: Adding plugins section with ProviderPlugin into webpack.config.js.
Read more >How i can solve Electron error: "Buffer is not defined"?-ember.js
Since Buffer isn't available on the web, you need to polyfill it. And since modern ember uses webpack, polyfilling Buffer is well documented....
Read more >Electron target version - Haxe - OpenFL Community
Hi Is there any way to bump the Electron target's version and still successfully compile and run an OpenFL app? ... Buffer is...
Read more >Buffer not defined in Webworker - Theia Community
The problem is that “Buffer” is not defined in the Worker that runs the plugins (see worker-main. ts).
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
Example file test.js:
var buf = new Buffer(1);
inside your main.js in electron:
Result:
I don’t understand why you had to incorporate webpack and all its spells in your example 😃 . I’m trying to get the app logic to isolate the bytenode aspect of the issue.
However, if you were able to solve the issue and get the app run by adding
Buffer = require("buffer").Buffer
, then you are correct: it’s the same issue discussed here. (and it can be demonstrated easily by usingBuffer
object in a very minimal electron setup). So, solving this problem requires that we study the source code of electron itself, to see where exactly the deletion ofBuffer
object occurs, and why this happens in the case of.jsc
files alone.I tried this approach before but did not spend much time on it. I’ll look into it again and get back to you.