Comments (15)
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.
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.
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.
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.
ok,i will try later
from node-flac-bindings.
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.
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.
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.
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.
Cool! I reinstalled the package and it works!!
from node-flac-bindings.
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.
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.
It's okay now, because my business logic has bugs
from node-flac-bindings.
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.
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)
- Can't instantiate flac.FileDecoder HOT 9
- prebuild-install WARN install No prebuilt binaries found (target=12.18.0 runtime=node arch=x64 libc= platform=win32) HOT 8
- Any documentation on how to write metadata to a flac file? HOT 5
- FLAC StreamDecoder unable to decode file when FileDecoder does HOT 17
- "Encoder has not been initialized yet" Error raised while using StreamEncoder HOT 7
- Installation fails on Android HOT 4
- Crashes on node 14.x HOT 2
- how to create metadata HOT 4
- Illegal instruction (Core dumped) error on Synology DS718+ HOT 10
- Decoder initialization failed: Error_opening_file HOT 26
- When I packaged the Electron project, it didn't work HOT 8
- Windows build errors HOT 11
- A specific song cannot be converted on windows HOT 16
- New release breaks my code HOT 8
- macbook pro m1, 13.2 (22D49) can't load libflac HOT 6
- Support for foreign metadata RIFF chunks HOT 3
- 24bit encoding HOT 7
- FLAC compressionLevel parameter is ignored HOT 5
- Miss check object on ptr HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-flac-bindings.