Search code examples
node.jstslint

TSlint Warning: deprecation atob is deprecated: Use `Buffer.from(data, 'base64')` instead


I have this warning when run lint on my project:

deprecation atob is deprecated: Use Buffer.from(data, 'base64') instead.

I´m trying to solve this warning by replace this line:

return JSON.parse(atob(token.split('.')[1]));

with the suggested solution showed in the console:

return JSON.parse(Buffer.from(token.split('.')[1],"base64"));

However, when debugging it shows the following error enter image description here

How can i solve this problem? I´m using node 14!


Solution

  • Fixed after changing:

    declare const Buffer: { from: (arg0: string, arg1: string) => string; };

    to

    import { Buffer } from 'buffer';