Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to detect nodeJS environment in the electron main process when using TypeScript and Webpack #70

Open
DeveloperBlue opened this issue Nov 10, 2022 · 7 comments

Comments

@DeveloperBlue
Copy link

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.

@jazz-soft
Copy link
Owner

Hi! Thank you for the notice!
Electron is not a Node.js environment.
Did you try https://github.com/jazz-soft/jazz-midi-electron ?

@DeveloperBlue
Copy link
Author

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.

@jazz-soft
Copy link
Owner

I made some Webpack fixes. Please check if that resolved your issue...

@nullobject
Copy link

The changes made in dab1c62 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"

@jazz-soft
Copy link
Owner

Did it work?

@nullobject
Copy link

Did it work?

Only after I made the change to the webpack configuration.

@jazz-soft
Copy link
Owner

Is your project available online? I'd like to look what the problem was...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants