Quick fixes to get em-fceux running as an npm module for node.js devs!

Issue #39 resolved
qashto created an issue

I submitted a pull request for the changes that must be made in package.json but in addition the code for setting the scriptDirectory is wrong when (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_WORKER)

you need to strip the “file:\\” from the beginning of the path since you’re loading the wasm from nodeFS

add this line:
scriptDirectory = scriptDirectory.slice(8);

With these two changes em-fceux will work in node.js as node users would expect it to. Please publish an update with these changes asap! Thanks again for all the work you’ve done on this project, I’m very excited to finally integrate it into Nostlan.

Comments (6)

  1. Valtteri Heikkilä repo owner

    I haven’t tested em-fceux on node or node+workers. So it may have some issues.

    I tried to repro this on Nostlan main branch but had no problems. (Though package.json was missing the main. Thanks for the PR.) The fceux.js, fceux.wasm, and NES games loaded fine. Confirment in the inspector.

    Are you using Windows? Could this be an OS difference, as I’m on a mac?

    If you want me to look into this, please provide a branch for some repro case for debugging. I have currently no test cases for node or node+workers.

  2. qashto reporter

    require('em-fceux') fails, you’re trying to read the wasm file with node fs which is good but it is impossible to use the “file://” url prefix. This isn’t an OS thing that’s just not how node works, it just uses system paths. No need to branch or test I already got it working with those two fixes, just add the line splicing the prefix off the scriptDirectory. I’ve included a picture for the context of where to add that line. idk where to change it in your source code, this is in the dist/fceux.js file.

    As for Nostlan, I’ve decided to run js emulators like this one in their own webview (loading through the script tag html) so this issue is no longer relevant for my use case. You should still implement this fix for other people who might want to use the module directly using require in node though!

  3. Valtteri Heikkilä repo owner

    Great you got it resolved and thanks for this great info! (Maybe I should create a nodejs or electron example as well.)

  4. qashto reporter

    That’d be nice but I think most node devs could figure out how to use it in nodejs based on the python minimal sample code you made (as long as it works as described ofc haha).

  5. Log in to comment