---
title: "Uso en navegador"
description: "Aprende a usar @nodecfdi/cfdi-core directamente en el navegador mediante el bundle IIFE global ncCfdiCore o con bundlers modernos."
canonical_url: "https://nodecfdi.com/packages/cfdi-core/getting-started/browser-usage"
---

> Index of every page on this site: [llms.txt](https://nodecfdi.com/llms.txt)

`@nodecfdi/cfdi-core` genera un bundle autocontenido en formato **IIFE** (`dist/index.iife.js`) compilado para `es2022`. Este bundle ya empaqueta `@xmldom/xmldom` y `decimal.js`, por lo que no requiere dependencias externas ni pasos de compilación para ejecutarse en el navegador.

## Carga mediante `<script>` (IIFE)

Al incluir `dist/index.iife.js`, toda la API pública queda expuesta bajo el objeto global `window.ncCfdiCore` (accesible también como `ncCfdiCore`).

<code-group>

```html [unpkg]
<script src="https://unpkg.com/@nodecfdi/cfdi-core/dist/index.iife.js"></script>
```

```html [jsDelivr]
<script src="https://cdn.jsdelivr.net/npm/@nodecfdi/cfdi-core/dist/index.iife.js"></script>
```

```html [Archivo local]
<script src="./node_modules/@nodecfdi/cfdi-core/dist/index.iife.js"></script>
```

</code-group>

## Ejemplo completo en HTML

Puedes desestructurar las clases y utilidades directamente desde `ncCfdiCore` para leer un XML, inspeccionar atributos, detectar su versión y limpiar razones sociales:

```html [index.html]
<!doctype html>
<html lang="es">
  <head>
    <meta charset="UTF-8" />
    <title>CFDI Core en Navegador</title>
  </head>
  <body>
    <pre id="output"></pre>

    <script src="https://unpkg.com/@nodecfdi/cfdi-core/dist/index.iife.js"></script>
    <script>
      const {
        XmlNode,
        nodeToXmlString,
        nodeFromXmlString,
        CfdiVersion,
        RegimenCapitalRemover,
      } = window.ncCfdiCore;

      // Construir un comprobante
      const comprobante = new XmlNode('cfdi:Comprobante', {
        Version: '4.0',
        Moneda: 'MXN',
        Total: '116.00',
      });
      comprobante.addChild(
        new XmlNode('cfdi:Emisor', {
          Rfc: 'EKU9003173C9',
          Nombre: 'ESCUELA KEMPER URGATE SA DE CV',
          RegimenFiscal: '601',
        }),
      );

      // Serializar y volver a leer
      const xml = nodeToXmlString(comprobante, true);
      const parsed = nodeFromXmlString(xml);

      // Descubrir versión y limpiar razón social
      const version = new CfdiVersion().getFromNode(parsed);
      const remover = RegimenCapitalRemover.createDefault();
      const nombreLimpio = remover.remove(
        parsed.searchAttribute('cfdi:Emisor', 'Nombre'),
      );

      document.getElementById('output').textContent = JSON.stringify(
        { version, nombreLimpio, xml },
        null,
        2,
      );
    </script>
  </body>
</html>
```

## Uso con bundlers (Vite, Nuxt, Webpack)

Si utilizas un bundler moderno en tu aplicación web, instala el paquete normalmente e importa la versión ESM estándar:

```ts [app.ts]
import { CfdiVersion, nodeFromXmlString } from '@nodecfdi/cfdi-core';

const version = new CfdiVersion().getFromXmlString(xmlString);
const root = nodeFromXmlString(xmlString);
```

<note>

El bundle IIFE no incluye las interfaces de TypeScript en tiempo de ejecución; para proyectos con TypeScript utiliza la importación ESM descrita en [Instalación](https://nodecfdi.com/packages/cfdi-core/getting-started/installation).

</note>

## Sitemap

See the full [sitemap](https://nodecfdi.com/sitemap.md) for all pages.
