node.js - node.js pathToFileURL()/fileURLToPath() 中是否有错误?
问题描述
我尝试了以下单元测试:
test('nodejs URL pathToFileURL() works', () => {
let dosPath = '\\\\?\\UNC\\diskstation\\home\\cpan-modules.txt'
let theUrl = pathToFileURL(dosPath);
let thePath = fileURLToPath(theUrl);
})
;
它失败了,但有以下异常:
TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
at getPathFromURLWin32 (internal/url.js:1310:13)
at Object.fileURLToPath (internal/url.js:1342:22)
at Context.<anonymous> (c:\<anonymized>\out\test\suite\extension.test.js:85:29)
at processImmediate (internal/timers.js:439:21)
该文件存在并且可以读取:
请注意,文档说这pathToFileURL()
将使 path absolute
. 这使得fileUrlToPath()
关于路径不是绝对的抱怨非常奇怪。
- https://nodejs.org/api/url.html#url_url_pathtofileurl_path
- https://nodejs.org/api/url.html#url_url_fileurltopath_url
我正在使用 VS-Code 1.43.1 开发一个 VS-Code 扩展
解决方案
推荐阅读
- django - Django REST Serializer 使用错误的模型进行序列化
- python - python文件写入程序运行时如何更新桌面上的文件大小
- javascript - 使用 d3.js 更新表数据
- c# - C#捕获从不在进程中的函数返回的异常?
- r - 如何设置仅在输入 3 时才显示集合向量的函数?
- javascript - 如果 URI 没有改变,例如在单页应用程序上,如何检测用户是否在新页面上?
- angular - Angular Kendo UI 全局访问
- php - 内连接循环通过
- git - 如何 git rebase 从另一个分支直接到 master 分支?
- javascript - 受控数字比例映射