Uncaught TypeError: URL is not a constructor using WHATWG URL object support for electron

前端 未结 4 944
自闭症患者
自闭症患者 2021-01-01 10:08

I am trying to read a file using WHATWG URL object support here

and I am getting this error: Uncaught TypeError: URL is not a constructor

here is my code:

4条回答
  •  渐次进展
    2021-01-01 10:45

    Node v10.0.0 and newer (currently Node v14.x)

    URL Class

    v10.0.0 | The class is now available on the global object.

    As mentioned here: Node.js Documentation - Class: URL

    So this should work without require('url'):

    const myUrl = new URL('http://example.com');
    

提交回复
热议问题