MTG / essentia.js

JavaScript library for music/audio analysis and processing powered by Essentia WebAssembly
https://essentia.upf.edu/essentiajs
GNU Affero General Public License v3.0
627 stars 41 forks source link

Package resolution when importing with ES module #111

Closed WangNianyi2001 closed 1 year ago

WangNianyi2001 commented 1 year ago

What is the issue about?

What part(s) of Essentia.js is involved?

Description

This is not really an unsolvable problem, but it did take me a while to figure the thing out, so I think it'd be helpful to write a issue of solution here for others to search for later.

So if you're using NPM and your project is in ES module flavor, the correct way to initialize Essentia should be:

import EssentiaPkg from 'essentia.js';
const { Essentia, EssentiaWASM: { EssentiaWASM } } = EssentiaPkg;
const essentia = new Essentia(EssentiaWASM);

Don't know why EssentiaWASM is wrapped in one more layer, but it is what it is. My installed version is essentia.js@0.1.3.

jmarcosfer commented 1 year ago

Thanks so much @WangNianyi2001!

Importing is a bit awkward for now indeed, so it's good to have this here.