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

188
Vistas
Why can I use import statements in libraries that only support CommonJS modules?

Ua-parser-js only supports the CommonJS module. And when exporting, the export statement is not found:

    if (typeof(exports) !== UNDEF_TYPE) {
        // nodejs env
        if (typeof module !== UNDEF_TYPE && module.exports) {
            exports = module.exports = UAParser;
        }
        exports.UAParser = UAParser;
    } else {
        // requirejs env (optional)
        if (typeof(define) === FUNC_TYPE && define.amd) {
            define(function () {
                return UAParser;
            });
        } else if (typeof window !== UNDEF_TYPE) {
            // browser env
            window.UAParser = UAParser;
        }
    }

Nevertheless, why can I import UAParser by import { UAParser } from 'ua-parser-js'? This code was shown in the following SO answer and GitHub issue.

https://stackoverflow.com/a/57171046

https://github.com/faisalman/ua-parser-js/issues/423

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are two ways how this might work:

  • Your toolchain does transpile the import { UAParser } from 'ua-parser-js' statement into the legacy const { UAParser } = require('ua-parser-js');, which is then executed by node
  • Node ESM do support importing CommonJS modules for compatibility. The module.exports = UAParser; will be available as the default import, the exports.UAParser = UAParser; will be available the a named import you're doing.
about 4 years ago · Juan Pablo Isaza Denunciar
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