How to use global URLSearchParams in node

后端 未结 4 1998
长发绾君心
长发绾君心 2020-12-18 18:23

I am writing a (client-side) JavaScript library (a node/angular module). In this library, I make use of the URLSearchParams class.

const form = new URLSearch         


        
4条回答
  •  Happy的楠姐
    2020-12-18 18:47

    You may use polifill @ungap/url-search-params https://www.npmjs.com/package/@ungap/url-search-params and for webpack may use @ungap/url-search-params/cjs

    Old NodeJS 8 (which isused in AWS and GCloud) does not support URLSearchParams so this polifill helps.

    In Node 10 when using TypeScript you may enable library dom which includes URLSearchParams implementation. Change tsconfig.json:

    {
      "compilerOptions": {
        "lib": [
          ...
          "dom"
          ...
        ]
      }
    }
    

提交回复
热议问题