4

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

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

Buffer class is available globally. Don't import it to avoid the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.