Quiero convertir una ruta de archivo a una URL.
Traté de seguir las indicaciones que se encuentran en los documentos oficiales: https://nodejs.org/dist/latest-v16.x/docs/api/url.html#urlpathtofileurlpath
import { pathToFileURL } from 'url' let filepathurl = pathToFileURL(file.path)Pero me sale este error:
Uncaught TypeError: (0 , _url.pathToFileURL) is not a functionO :
import url from 'url' let filepathurl = url.pathToFileURL(file.path)Mensaje de error:
_url.default.pathToFileURL is not a functionOtra información:
node: v16.13.0 OS : Ubuntu 20.04 Desktop¿Qué estoy haciendo mal? ¿Como resolver el problema?
Ejemplo de ruta de archivo:
/home/raphy/Downloads/sample.pdfPor el momento, resolví el problema usando https://www.npmjs.com/package/file-url combinado con esta útil sugerencia para la configuración del paquete web: https://github.com/facebook/create-react-app/pull /11764#issuecomentario-1104019653
Pero me gustaría saber si y cómo usar correctamente las funciones de la biblioteca node.js