Reputation: 1651
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?
Upvotes: 1
Views: 15
Reputation: 1651
The comment from @bojan-kogoj directed me into the right direction.
The Update automatically changed my angular.json from
"builder": "@angular-devkit/build-angular:browser"
to
"builder": "@angular-devkit/build-angular:application"
After setting it back to browser
everthing works just fine again
Upvotes: 1