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

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

    Are you using Node 6 instead of Node 8?

    Node 6

    const url = require('url');
    const myUrl = url.parse('http://example.com');
    const myUrlString = url.format(myUrl);
    

    https://nodejs.org/dist/latest-v6.x/docs/api/url.html#url_url

    Node 8

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

    https://nodejs.org/dist/latest-v8.x/docs/api/url.html#url_url

提交回复
热议问题