zhuker/lamejs

"MPEGMode is not defined"

DonLifeScore opened this issue ยท 21 comments

Hi.

I'm hitting an error in the new update (1.2.1 vs. 1.2.0):

Uncaught (in promise) ReferenceError: MPEGMode is not defined
at Lame.js:135
at e.lame_init (Lame.js:229)
at new e.exports.Mp3Encoder (index.js:100)
at export-audio.js:80

Where I'm call this:

const mp3_bitRateKbps = 256;
const mp3_sampleRate = 44100;
const mp3encoder = new lamejs.Mp3Encoder(2, mp3_sampleRate, mp3_bitRateKbps);

-- Don Tillman

Hi Don, same here! The previous fix unfortunately caused some issues with modules relying on implicitly & improperly loaded submodules. The following changes fix at least my pipeline, I hope yours as well. Until there is a new version out, you need to edit the respective files in your node_modules/lamejs folder. After the filename I give the line number to insert the requirement.

Lame.js:29
Encoder.js:112
PsyModel.js:162
all need var MPEGMode = require('./MPEGMode.js');

BitStream.js:33
Presets.js:18
both need var Lame = require('./Lame.js');

QuantizePVT.js:54
needs var BitStream = require('./BitStream.js');

Specy commented

Also having the same issue with sveltekit, waiting for PR to be merged and new version deployed

T0914 commented

Any update on this conversation guys ? I have the same issue

I'm still having to make these manual changes despite using 1.2.1.

same issue too

I was using this approach to linking with unreleased deps for a while and it was working, but at the moment for me neither that approach nor direct linking to 1.2.1 works. This issue shouldn't have been closed yet; we need a working release thanks!

(BTW, I found that unlinking on both ends and re-linking did the trick, but a new release would be so much easier)

I have the same issue still. Why is it closed?

still

Try audio-encoder npm . works.

Try audio-encoder npm . works.

it seems audio-encoder uses lamejs and i have the same err ;(
just copied their example to my app
Selithrarion/vue_audio-tools@391fd2f

It's pretty dirty, but this repo fixed it for me if you don't want to manually each time:
https://www.npmjs.com/package/lamejstmp

It's dirty as hell of course, I hope this gets resolved.

Also, this repo might do what most people want with less boilerplate, it has lamejs bundled into it and doesn't suffer from this issue:
https://github.com/closeio/mic-recorder-to-mp3

Is there something I'm missing about this? The issue has been closed for a while, but I am still experiencing the same problem. This fix works, when can it be expected to be included in production?

Hi Don, same here! The previous fix unfortunately caused some issues with modules relying on implicitly & improperly loaded submodules. The following changes fix at least my pipeline, I hope yours as well. Until there is a new version out, you need to edit the respective files in your node_modules/lamejs folder. After the filename I give the line number to insert the requirement.

Lame.js:29 Encoder.js:112 PsyModel.js:162 all need var MPEGMode = require('./MPEGMode.js');

BitStream.js:33 Presets.js:18 both need var Lame = require('./Lame.js');

QuantizePVT.js:54 needs var BitStream = require('./BitStream.js');

The issue is fixed in the latest release on Github, just not on NPM apparently. You can use this as a workaround in your package.json:

"dependencies": {
    "lamejs": "github:zhuker/lamejs"
}

The issue is fixed in the latest release on Github, just not on NPM apparently. You can use this as a workaround in your package.json:

"dependencies": {
    "lamejs": "github:zhuker/lamejs"
}

Great! Worked for me.

@viniciusgusmao it doesn't work for me :(

@viniciusgusmao it doesn't work for me :(

could be you're using mic-recorder like i was and this one carries a 3 year old version of lamejs which you will have to manually override, even with this solve from @jgentes
at least i did, although it somewhat contradicts my understanding of it having lamejs as a dependency, here's sharing hope you can use it to solve your issue too

@TVNielsen Im using lamejs directly

Declaring global variables can help:

import MPEGMode from 'lamejs/src/js/MPEGMode';
import Lame from 'lamejs/src/js/Lame';
import BitStream from 'lamejs/src/js/BitStream';


window.MPEGMode = MPEGMode;
window.Lame = Lame;
window.BitStream = BitStream;

@viniciusgusmao it doesn't work for me :(

have you done npm install after changing package.json ?