2024-11-24 15:18:06 +00:00
|
|
|
# Angular 17.3.0 xlsx audio buffer
|
2024-11-24 14:22:26 +00:00
|
|
|
|
2024-11-24 15:18:06 +00:00
|
|
|
Resolves "Buffer is not constructor" error in Angular 17 and demonstrates correct Buffer polyfill setup in a minimal working example.
|
2024-11-24 14:22:26 +00:00
|
|
|
|
|
|
|
|
2024-11-24 15:18:06 +00:00
|
|
|
When working with `Buffer` in Angular 17, you might encounter the error:
|
2024-11-24 14:22:26 +00:00
|
|
|
|
2024-11-24 15:18:06 +00:00
|
|
|
```ts
|
|
|
|
Buffer is not constructor
|
|
|
|
var global = global || window;
|
|
|
|
var Buffer = Buffer || [];
|
|
|
|
```
|
2024-11-24 14:22:26 +00:00
|
|
|
|
2024-11-24 15:18:06 +00:00
|
|
|
### 1. Install dependencies
|
|
|
|
```bash
|
|
|
|
pnpm rm xlsx
|
|
|
|
pnpm buffer
|
|
|
|
pnpm install --save https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz
|
|
|
|
```
|
|
|
|
### 2. Create/update polyfills.ts
|
|
|
|
```ts
|
|
|
|
import { Buffer } from 'buffer';
|
|
|
|
(window as any).Buffer = Buffer;
|
|
|
|
```
|
2024-11-24 14:22:26 +00:00
|
|
|
|
|
|
|
|
2024-11-24 15:18:06 +00:00
|
|
|
### Running the Demo
|
|
|
|
* Don't set up Buffer in index.html
|
|
|
|
* Don't use new Buffer() (deprecated)
|
2024-11-24 14:22:26 +00:00
|
|
|
|
2024-11-24 15:18:06 +00:00
|
|
|
### What This Demo Includes
|
|
|
|
* Proper Buffer polyfill setup
|
|
|
|
* Binary data handling example
|
|
|
|
* File processing with SheetJS
|
|
|
|
* Working audio file metadata extraction
|