Closed DrCWO closed 9 months ago
Next I tried to dynamically import so I did:
var flacBindings = require('flac-bindings');
instead of
var flacBindings = require('flac-bindings');
But then I get an error in the next line if I like to create an instance of StreamEncoder:
/home/pi/rooExtend/modPlay.js:928
var encoder = new StreamEncoder({
^
TypeError: StreamEncoder is not a constructor
OK, for all with the same issue I will publish the solution 👍
This was the code before:
var flacBindings = require('flac-bindings');
StreamEncoder = flacBindings.StreamEncoder;
// ... your code continues here...
This is the code that you have to use now. It dynamically loads the module and this takes some time. Therefore you have to wait and continue asynchronously...
import('flac-bindings')
.then(flacBindings => {
StreamEncoder = flacBindings.StreamEncoder;
// ... after loading the flac-bindings your code continues here...
})
.catch(err => {
console.log('Cannot load flac-bindings ' + err);
})
Hope this is useful for someone else but me.
@melchor629 will be great if you might add this to your README file
Best DrCWO
Hi DrCWO! Thanks for opening the issue.
This is a known "pain point" of the 3.x series. In release notes I pointed it out that this was happening and added this link https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c which explains a bit what happens and what you can do to fix it. You can always keep using 2.x series meanwhile or use the dynamic import()
syntax.
In addition, because I imagined that this would be a recurrent issue, the README also contains this line to warn the devs. I see I should make it even clearer.
Sorry for this confusion. I wanted to move forward with the technology and I know that this can be a bit frustrating. I hope you could find the above link useful.
I had the same issue. might be worth adding to the comment to use v2.x if you need CommonJS support? https://github.com/melchor629/node-flac-bindings/tree/v2.7.2
Added a note for it in the readme just in case, thanks
added a custom bundle with cjs under require('flac-bindings')
in latest version
So can we now upgrade v2 to v3 without any issues? @melchor629
Give it a try and let's hope nothing breaks. In my really limited testing, everything seem to work fine, but it may have any unwanted surprise. Raise an issue if you find something not working.
I currently use "flac-bindings": "^3.0.0", with node v19.0.0
In the code I ran on node v16 I used "flac-bindings": "^2.7.0" and ran fine.
Here my code that runs fine with v2.7.0 on node v16:
Running with v3.0.0 on node v19 I get:
Changing my code as recommended to
import { StreamEncoder } from 'flac-bindings';
I see this error:
Help would be appreciated as I have to finish my new release and am stuck at that point.
Thanks' DrCWO