Uncaught TypeError:URL不是使用WHATWG URL对象对电子的支持的构造函数 [英] Uncaught TypeError: URL is not a constructor using WHATWG URL object support for electron

查看:30
本文介绍了Uncaught TypeError:URL不是使用WHATWG URL对象对电子的支持的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用WHATWG URL对象支持读取文件此处

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

,并且出现此错误:Uncaught TypeError:URL不是构造函数

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

这是我的代码:

var fs = require("fs");                                     
const { URL } = require('url');
var dbPath = 'file://192.168.5.2/db/db.sqlite';
const fileUrl = new URL(dbPath);

推荐答案

我遇到了同样的问题,然后研究了url模块并找到了解决方案

I faced the same issue, then I looked into the url module and found a solution

供节点V6 使用,

const URL = require('url').Url;

const { Url } = require('url'); 

如果您查看模块,它将导出5种方法,其中一种是Url,因此如果需要要访问网址,可以使用两种方法之一

If you look into the module, it exports 5 methods one of which is Url, so if you need to access Url, you can use either of the two methods

这篇关于Uncaught TypeError:URL不是使用WHATWG URL对象对电子的支持的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆