File tree 1 file changed +18
-5
lines changed
1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -771,17 +771,30 @@ Dependency list:
771
771
772
772
## CommonJS backward compatibility
773
773
774
- For legacy CommonJS projects needing to load the ` music-metadata ` ESM module, you can use the ` loadMusicMetadata ` function:
774
+ Using Node.js ≥ 22, which is support loading ESM module via require
775
775
``` js
776
- const { loadMusicMetadata } = require (' music-metadata' );
776
+ const mm = require (' music-metadata' );
777
+ ```
777
778
779
+ For older Node.js version < 22, you need to dynamically import ** music-metadata** :
780
+ ``` js
778
781
(async () => {
779
782
// Dynamically loads the ESM module in a CommonJS project
780
- const mm = await loadMusicMetadata ();
781
-
782
- const metadata = await mm .parseFile (' /path/to/your/file' );
783
+ const mm = await import (' music-metadata' );
783
784
})();
785
+ ```
786
+
787
+ For CommonJS TypeScript projects, using a Node.js version < 22, you can use [ load-esm] ( https://github.com/Borewit/load-esm ) :
788
+
789
+ This method replaced the CJS loader ` loadMusicMetadata() ` function.
784
790
791
+ ``` js
792
+ import {loadEsm } from ' load-esm' ;
793
+
794
+ (async () => {
795
+ // Dynamically loads the ESM module in a CommonJS project
796
+ const mm = await loadEsm< typeof import (' music-metadata' )> (' music-metadata' );
797
+ })();
785
798
```
786
799
787
800
> [ !NOTE]
You can’t perform that action at this time.
0 commit comments