Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

481
Vistas
url.pathToFileURL is not a function : how to convert a file path to an URL in node.js?

I want to convert a file path to an URL.

I tried to follow the indications found in the official docs: https://nodejs.org/dist/latest-v16.x/docs/api/url.html#urlpathtofileurlpath

import { pathToFileURL } from 'url'

let filepathurl = pathToFileURL(file.path)

But I get this error:

Uncaught TypeError: (0 , _url.pathToFileURL) is not a function

Or :

import url from 'url'
let filepathurl = url.pathToFileURL(file.path)

Error message:

_url.default.pathToFileURL is not a function

Other info:

node: v16.13.0
O.S. : Ubuntu 20.04 Desktop

What am I doing wrongly? How to solve the problem?

Example of file path:

/home/raphy/Downloads/sample.pdf

At the moment, I solved the problem using https://www.npmjs.com/package/file-url combined with this helpful suggestion for webpack configuration: https://github.com/facebook/create-react-app/pull/11764#issuecomment-1104019653

But I would like to know if and how to correctly use the features of the node.js library

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda