Code Monkey home page Code Monkey logo

Comments (15)

zhushenwudi avatar zhushenwudi commented on June 10, 2024 1

thx, I saw that the discussion result was not solved for the time being, then there is no way.
3.0.0 still has half a second empty frame. Let me close this issue temporarily

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 10, 2024

Hi again! The error you are facing is totally expected. That's one of the breaking changes of version 3.0.

See https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c which has a good FAQ about ES Modules, and also could be interesting this from node docs.

State of ESM imports in Electron has a dedicated issue in their repo.

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

The current situation is that Electron does not support this import mode, and the official has not provided a solution, is that so?

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 10, 2024

Yep, sadly that's more or less the current state. The good thing is node already provides a workaround for this, but depends on the tools you use. import('package') can be used anywhere to load any kind of package (including ESM). The bad part is that TypeScript or bundlers like webpack will rewrite the import() to anything else. I think there is some package around to workaround this. Take a look at the first link I sent you, it gives some tips to face this issue.

A quick expample to convert normal import with dynamic import would be:

// On the top of the file
import { StreamDecoder } from 'flac-bindings';

// Wherever you want, but it should support await
const { StreamDecoder } = await import('flac-bindings');

Sorry for the inconvenience, I had this planned a long time ago already... :(

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

ok,i will try later

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

upgrade to [email protected], because I saw this merge info:
electron/electron#35930
I use "const { FileDecoder } = await import('flac-bindings');"
it's not work

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/index.js from /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts not supported.
Instead change the require of index.js in /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts to a dynamic import() which is available in all CommonJS modules.
at require.extensions. [as .js] (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:851:20)
at c._load (node:electron/js2c/asar_bundle:5:13339)
at /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts:234:81
at async /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts:234:33
(node:35675) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/index.js from /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts not supported.
Instead change the require of index.js in /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts to a dynamic import() which is available in all CommonJS modules.
at require.extensions. [as .js] (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:851:20)
at c._load (node:electron/js2c/asar_bundle:5:13339)
at /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts:234:81
at async /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts:234:33
(node:35675) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 10, 2024

Them, as I mentioned before, the import() is getting rewritten (probably thanks to typescript). Read this https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-import-esm-in-electron , hope it helps. I have used it sometime ago and worked fine.

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

I switch the module of ts-node as esm, and use [email protected], because when i use [email protected], official use v8 memory cages and limit 4g heap memory, maybe glasstron-clarity native-module is not compatible.

I also use these code

const {FileDecoder} = await import("flac-bindings")
let decoder = new FileDecoder({
    file: srcPath,
})

But there are still some internal errors in flac binding.

TypeError: flac.DecoderBuilder is not a constructor
    at new FileDecoder (file:///Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/decoder/file-decoder.js:10:21)
    at /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts:218:23
(node:80726) UnhandledPromiseRejectionWarning: TypeError: flac.DecoderBuilder is not a constructor
    at new FileDecoder (file:///Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/decoder/file-decoder.js:10:21)
    at /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts:218:23
(node:80726) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

perhaps flac.DecoderBuilder in file-decoder.js is not a constructor

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 10, 2024

Well, now at least it imports the package, that is some good news.

The error now it might be because the native code (the .node file) has not been updated properly. That class de error references is new and comes from that native code.

I might have an issue in the downloader. Try to run a npm rebuild and see if it fixes the issue. Or reinstall the package.

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

Cool! I reinstalled the package and it works!!

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

However, the song previously mentioned cannot be played directly when it is converted by version 3.0.0, which is not only a problem of half frame loss

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

However, the song previously mentioned cannot be played directly when it is converted by version 3.0.0, which is not only a problem of half frame loss

roll back to v2.7.2 is also not work. It's strange. Let me think about it again

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

It's okay now, because my business logic has bugs

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 10, 2024

In addition, I want to know what is the difference between 2 and 3, and what are the optimizations or bug fixes in addition to the conversion bit esm

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 10, 2024

Oh good to now that 3.0 seems to work fine now :)

Regarding changes from 2.7 to 3.0, there are some good breaking changes:

  • update to libFLAC 1.4.1 (from 1.3.something)
  • some refactors in the native code for people that use the native API directly (you faced with the flac.DecoderBuilder which is a new class in native code)
  • removed support for node 10 and 12 mainly for not being supported anymore
  • officially adding Windows x86 builds
  • the script to download the native code is not a dependency anymore, I maintain a specific version for my use case (one dependency less to install)

Big changes come from the update of libFLAC (see their release notes).

from node-flac-bindings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.