I am debugging a lambda function locally on Node 4.3 using the standard Amazon Machine Image (linux x64)
When I run the program, I get an error in a function that is meant to decode a base64 string to utf-8. The error says
Unhandled rejection TypeError: base64 is not a function
at Function.from (native)
at Function.from (native)
at /home/ec2-user/sass-compiler/lib/compiler.module.js:26:30
My code seems rather simple. I have checked around SO and the node 4.3 docs and my code seems compliant. Any ideas what I might be doing wrong?
template() {
return new Promise((resolve, reject) => {
let buf = Buffer.from(this._opts.tpl, 'base64').toString('utf-8');
let _tpl = _.template(buf);
resolve(_tpl(this._opts.opts));
});
}
EDIT The program works just fine on Windows 10 using Node LTS 6.9.5
I finally found an answer on Stack Overflow that answers this question.
NodeJS: How to decode base64 encoded string back to binary?
In node 5.3 & below, you need to use the buffer constructor (ie: new Buffer
) instead of Buffer.from
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With