DeprecationWarning: Buffer() is deprecated due to security and usability issues when i move my script to another server

前端 未结 3 856
独厮守ぢ
独厮守ぢ 2020-12-02 07:09

Getting error when script move to other server.

(node:15707) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issue

相关标签:
3条回答
  • 2020-12-02 07:46
    var userPasswordString = new Buffer(baseAuth, 'base64').toString('ascii');
    

    Change this line from your code to this -

    var userPasswordString = Buffer.from(baseAuth, 'base64').toString('ascii');
    

    or in my case, I gave the encoding in reverse order

    var userPasswordString = Buffer.from(baseAuth, 'utf-8').toString('base64');
    
    0 讨论(0)
  • 2020-12-02 08:07
    new Buffer(number)            // Old
    Buffer.alloc(number)          // New
    

    new Buffer(string)            // Old
    Buffer.from(string)           // New
    

    new Buffer(string, encoding)  // Old
    Buffer.from(string, encoding) // New
    

    new Buffer(...arguments)      // Old
    Buffer.from(...arguments)     // New
    

    Note that Buffer.alloc() is also faster on the current Node.js versions than new Buffer(size).fill(0), which is what you would otherwise need to ensure zero-filling.

    0 讨论(0)
  • 2020-12-02 08:07

    The use of the deprecated new Buffer() constructor (i.E. as used by Yarn) can cause deprecation warnings. Therefore one should NOT use the deprecated/unsafe Buffer constructor.

    According to the deprecation warning new Buffer() should be replaced with one of:

    • Buffer.alloc()
    • Buffer.allocUnsafe() or
    • Buffer.from()

    Another option in order to avoid this issue would be using the safe-buffer package instead.

    You can also try (when using yarn..):

    yarn global add yarn
    

    as mentioned here: Link

    Another suggestion from the comments (thx to gkiely): self-update

    Note: self-update is not available. See policies for enforcing versions within a project

    In order to update your version of Yarn, run

    curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
    
    0 讨论(0)
提交回复
热议问题