Buffer is undefined in electronSee original GitHub issue
If 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.
- Created 5 years ago
Top GitHub Comments
Example file test.js:
var buf = new Buffer(1);
inside your main.js in electron:
v8.setFlagsFromString('--no-lazy'); bytenode.compileFile('./test.js', './test.jsc'); require('./test.jsc');
TypeError: undefined is not a constructor at Object.<anonymous> (evalmachine.<anonymous>:1:167) at Object.<anonymous> (evalmachine.<anonymous>:1:185)```
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 using
Buffer 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 of
Buffer 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.