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

前端 未结 4 938
自闭症患者
自闭症患者 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:35

    The docs you took this info out are for the node of version 8.4.0.

    If it does not work for you, that means that your node is of version 6.11.2. Then, just change the letter case of URL -

    const { Url } = require('url');
    const myUrl = new Url('http://example.com'); 
    

    because url module exports Url, not URL.

提交回复
热议问题