0

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?

4
  • 1
    Did you change builder in angular.json? Commented Jan 30 at 13:43
  • @bojan-kogoj This was actually a good call. Seems like the angular update automatically change "builder": "@angular-devkit/build-angular:browser" to "builder": "@angular-devkit/build-angular:application". After reverting this, everything works just fine Commented Jan 30 at 13:53
  • You likely have a dependency issue, with 2 different core modules getting bundled together. Commented Jan 30 at 16:16
  • @MatthieuRiegler thanks for your response. Do you have any idea how I could find out which modules trigger this error by beeing bundled together? Commented Jan 31 at 9:13

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

This is not a solution, but a strange workaround. The new application builder has better perf and the old one is no longer maintained.
It's a common workaround. Even browser-esbuild has issues with some libraries unfortunately

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.