benrr101 / node-taglib-sharp

A node.js port of mono/taglib-sharp
GNU Lesser General Public License v2.1
34 stars 9 forks source link

'Cannot set property ByteVector' error on load of module #87

Open the0neWhoKnocks opened 7 months ago

the0neWhoKnocks commented 7 months ago

Within file file.mjs I have:

import { File } from 'node-taglib-sharp';

When trying to load that file I get this error:

TypeError: Cannot set property ByteVector of #<Object> which has only a getter
    at Object.<anonymous> (/home/node/app/node_modules/node-taglib-sharp/dist/index.js:3:1200)

I'm able to get the file to load by changing file.mjs to:

import { File } from 'node-taglib-sharp/dist/file.js';

but then it fails with:

/home/node/app/node_modules/node-taglib-sharp/dist/file.js:113
    throw new Error(`Unsupported format: mimetype for ${abstraction.name} (${mimeType}) is not supported`);

because I'm guessing that File._fileTypes gets set within the main module.

The file is being loaded directly (no pre-processing involved).

Running:

the0neWhoKnocks commented 7 months ago

Had to go all the way back to node-taglib-sharp@3.3.1 to get it to run.

benrr101 commented 7 months ago

Hi @the0neWhoKnocks, thanks for reporting this issue. I'm not a huge javascript developer, so it's entirely possible there's something I missed with the setup for the package. For background, this project is written in typescript and compiled as a CommonJS module for ES6. I remember a while back reading about compatibility issues between CommonJS and ECMAscript modules that prompted some change in compilation process probably around v3.3. The package is tested against Node v14.21.3 to allow for as much backwards compatibility as feasible. All integration testing is done from typescript. I can try upgrading to Node v20, but it'll take me a bit to get setup with ECMAscript modules to verify it works in your scenario.

In the meantime... You're sorta correct that loading the File._fileTypes gets populated by the main module. The index imports/exports all the different classes that inherit from File and at the bottom of each of those files it registers itself within File._fileTypes for the various mime-types it supports. As a potential workaround, you can try importing the specific file type you want to use (eg, MpegAudioFile) and create the file object using new MpegAudioFile("pathToFile"). If that gives any errors, that will be additional data points to help resolve this issue.

the0neWhoKnocks commented 7 months ago

Ended up switching everything over to CommonJS last week to get things to work with the new version.

Good luck finding the config option to get TS to compile cjs correctly. If there is no solution, maybe note in the doc that it currently won't work in mjs files.