How do I get node's core modules working with Angular v18?

Discussão em 'Angular' iniciado por brianb08, Dezembro 6, 2024.

  1. brianb08

    brianb08 Guest

    I'm attempting to use microphone-stream which depends on readable-stream in an Angular v18 application. When running locally I receive a series of errors in the console related to globals, Buffer, and process objects all missing, which are core modules from node. I believe these must be polyfilled into the app, but I can't figure out how to do this.

    There appears to be a very good vite plugin to do this: vite-plugin-node-polyfills but it seems that the vite configuration for angular can't be customized with plugins.

    My app is using the standard Angular application builder (from angular.json):

    ...
    "architect": {
    "build": {
    "builder": "@angular-devkit/build-angular:application",
    ...


    I did try creating installing the process and buffer and including them in a polyfill like this:

    window.global = window
    var process = require('process')
    var Buffer = require('buffer/').Buffer


    But that didn't work either. I do realize they are quite old.

    Continue reading...

Compartilhe esta Página