Angular protobuf injection error after update

Discussão em 'Angular' iniciado por Felix Gerber, Janeiro 30, 2025.

  1. Felix Gerber

    Felix Gerber Guest

    I got an angular application which I wanted to update from version 18 to 19. The update was executed like described in the offical update guide

    Within this application im using protobuf.js.

    Before the update I was able to import like its mentioned in the offical documentation:

    var protobuf = require("protobufjs/minimal");


    But after the update I am getting this error:


    Uncaught Error: Dynamic require of "protobufjs/minimal" is not supported
    ​

    While searching for a fix I came up with this solution:

    import * as $protobuf from "protobufjs/minimal";


    But this produces another error in my main.ts:


    ERROR RuntimeError: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext. Find more at https://angular.dev/errors/NG0203 at injectInjectorOnly (core.mjs:1104:11) at ɵɵinject (core.mjs:1114:40) at ɵɵdirectiveInject (core.mjs:11821:12) at NodeInjectorFactory.AppComponent2_Factory [as factory] (ɵfac.js:1:1) at getNodeInjectable (core.mjs:5315:38) at createRootComponent (core.mjs:17557:31) at ComponentFactory.create (core.mjs:17436:21) at _ApplicationRef.bootstrap (core.mjs:23007:38) at core.mjs:35186:56 at Array.forEach ()
    ​

    The error occures while executing the following code:

    platformBrowserDynamic().bootstrapModule(AppModule)
    .catch(err => console.error(err));


    One interesting fact. I did not change my AppModule at all. I just updated from Angular 18 to 19. Any ideas on how to fix this?

    Continue reading...

Compartilhe esta Página