axenda / zatca

An unofficial package to help developers implement ZATCA (Fatoora) QR code easily which is required for e-invoicing in Saudi Arabia.
MIT License
51 stars 13 forks source link

Buffer is not defined #11

Closed geowasim closed 2 years ago

geowasim commented 2 years ago

Uncaught ReferenceError: Buffer is not defined at toHex (to-hex.js:14:1) at Tag.toTlv (tag.js:19:1) at to-tlv.js:10:1 at Array.map () at toTlv (to-tlv.js:10:1) at _c (ComponentToPrint.js:17:1) at renderWithHooks (react-dom.development.js:16305:1) at updateForwardRef (react-dom.development.js:19226:1) at beginWork (react-dom.development.js:21636:1) at beginWork$1 (react-dom.development.js:27426:1)

**It's work fine on codesandbox** 
_but when it comes to npx create-react-app I get this message_ 

I downloaded Buffer as backage, but it didn't help

import { Invoice } from "@axenda/zatca";

function App() { console.log(Invoice); --- ok

const invoice = new Invoice({ sellerName: "Axenda", vatRegistrationNumber: "1234567891", invoiceTimestamp: "2021-12-04T00:00:00Z", invoiceTotal: "100.00", invoiceVatTotal: "15.00", });

console.log(invoice.toTlv()); --- throw error in console .....

geowasim commented 2 years ago

I guess one line solve the problem I added : window.Buffer = Buffer; inside the file

import { Invoice } from "@axenda/zatca"; import {Buffer} from "buffer";

function App() { window.Buffer = Buffer;

const invoice = new Invoice({ sellerName: "Axenda", vatRegistrationNumber: "1234567891", invoiceTimestamp: "2021-12-04T00:00:00Z", invoiceTotal: "100.00", invoiceVatTotal: "15.00", });

mparvej89 commented 1 year ago

Thanks but using this its not solved I got another solution import * as Buffer from '../node_modules/buffer/index'; (window as any).global = window; (window as any).process = {}; (window as any).process = window; (window as any).process.browser = true; (window as any).process.version = ''; (window as any).process.versions = { node: false }; (window as any).global.Buffer = Buffer.Buffer;

These are need to add in polyfills.ts then issue resolve