JZZ
JZZ copied to clipboard
Fails to detect nodeJS environment in the electron main process when using TypeScript and Webpack
When using jzz (and it's dependency jazz-midi) in an electron main process written in Typescript and transpiled with Webpack, a dynamic require found in JZZ.js does not work and the library fails to detect that it is in a NodeJS environment.
It is similar to the issue found at jazz-soft/jazz-midi#6
A workaround would be to apply the patch mentioned here as well as the following:
_initNode(require('jazz-midi')); // https://github.com/jazz-soft/JZZ/blob/master/javascript/JZZ.js#L575
should be changed to
const require_dynamic = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
_initNode(require_dynamic('jazz-midi'));
I'm not sure if typescript/webpack/electron issues are within the scope of this project, but I thought I would mention the fix I'm using.
Hi! Thank you for the notice! Electron is not a Node.js environment. Did you try https://github.com/jazz-soft/jazz-midi-electron ?
Hi! Electron has two process models, the main process (a NodeJS environment) and a renderer process (the browser/chromium environment that you are thinking about). This issue is for the main process, which is a NodeJS environment.
The issue is not really caused by Electron directly, but by Webpack being unable to detect the dynamic require when generating the JavaScript bundles.
Personally, I would not change anything in jzz or jazz-midi because so few people will run into this problem, I recommend just adding a small note in the READMEs for anyone using a JavaScript bundler (Webpack, Gulp, Babel, Browserify, etc.). Even this issue existing is enough, as someone will probably find it while they are troubleshooting.
I made some Webpack fixes. Please check if that resolved your issue...
The changes made in https://github.com/jazz-soft/JZZ/commit/dab1c62c04a2a0043bba8037080b425704b8badc did not fix the webpack issue for me.
I had to add the jazz-midi package to the externals defined in the webpack.main.config.ts file:
externals: "jazz-midi"
Did it work?
Did it work?
Only after I made the change to the webpack configuration.
Is your project available online? I'd like to look what the problem was...