Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic require of "google-protobuf" is not supported #26833

Closed
1 task done
ivegotwings opened this issue Jan 10, 2024 · 8 comments · Fixed by #26956
Closed
1 task done

Dynamic require of "google-protobuf" is not supported #26833

ivegotwings opened this issue Jan 10, 2024 · 8 comments · Fixed by #26956

Comments

@ivegotwings
Copy link

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

16.0.0

Description

The error comes when we call the loadFormFields method in the project/schema library. This used to work perfectly fine in version 16. The demo project resembles the structure of the real project that we work on, so we cannot make changes to the code structure or remove the function call.

Minimal Reproduction

  1. run- npm run start
  2. launch the browser
  3. open console

minimal reproduction depo project- https://github.com/ivegotwings/angularclibug

Exception or Error

`
chunk-XD6TBTUO.js:12 Uncaught Error: Dynamic require of "google-protobuf" is not supported
    at chunk-XD6TBTUO.js:12:9
    at projects/schema/src/lib/model/pbjs/extschema/ves.io/schema/errors_pb.js (errors_pb.js:11:12)
    at __require2 (chunk-XD6TBTUO.js:21:50)
    at index.ts:3:15
`

Your Environment

Angular CLI: 17.0.9
Node: 20.10.0
Package Manager: npm 10.2.3
OS: darwin x64

Angular: 17.0.8
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.9
@angular-devkit/build-angular   17.0.9
@angular-devkit/core            17.0.9
@angular-devkit/schematics      17.0.9
@angular/cli                    17.0.9
@schematics/angular             17.0.9
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

Anything else relevant?

No response

@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely area: devkit/build-angular devkit/build-angular:dev-server type: bug/fix severity3: broken and removed freq1: low Only reported by a handful of users who observe it rarely area: devkit/build-angular devkit/build-angular:dev-server labels Jan 10, 2024
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jan 10, 2024

Whlist there is a problem in the dev-server when using require. It is worth mentioning that dynamic imports that use string literals such as import('./model/pbjs/extschema/ves.io/schema/${entity}/form-fields.js') will not longer work with the esbuild pipeline.

See: evanw/esbuild#56

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jan 25, 2024
…as externals

Prior to this change any module which was used using `require` was not listed as an external.

See angular#26833
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jan 25, 2024
…ls imports

Prior to this change any module which was used using `require` was not listed as an external.

Closes angular#26833
alan-agius4 added a commit that referenced this issue Jan 25, 2024
…ls imports

Prior to this change any module which was used using `require` was not listed as an external.

Closes #26833
alan-agius4 added a commit that referenced this issue Jan 25, 2024
…ls imports

Prior to this change any module which was used using `require` was not listed as an external.

Closes #26833

(cherry picked from commit d6aea27)
@MartinToewsWI
Copy link

I think the bug is with Version 17.1.2 still alive...

I got the same error with application builder and @angular-devkit/build-angular version 17.1.2

@davide1995
Copy link

Suffering the same problem with Angular 17.1.3:

Uncaught Error: Dynamic require of "@angular/core" is not supported
    at main.js:12:9
    at libs/tod-api/api/authentication.service.js (authentication.service.ts:14:1)
    at __require2 (main.js:15:50)
    at libs/tod-api/api/api.js (api.ts:1:1)
    at __require2 (main.js:15:50)
    at libs/tod-api/index.js (index.ts:1:1)
    at __require2 (main.js:15:50)
    at app.config.ts:6:56

@BastianKamp
Copy link

Same error with @angular-devkit/build-angular version 17.2.1

Uncaught Error: Dynamic require of "google-protobuf" is not supported
    at chunk-BIE6XYAC.js:29:9
    at libs/grpc/src/lib/protos/generated/dto_pb.js (dto_pb.js:14:12)
    at __require2 (chunk-BIE6XYAC.js:32:50)
    at grpc-wire.ts:5:37

@BastianKamp
Copy link

@alan-agius4 can you open the issue again? As others have noted, it is not solved. I have tested the behavior with 17.1.4. and 17.2.1.

@arobinson
Copy link

arobinson commented Mar 5, 2024

I'm not sure if this is the same issue, but I'm getting the error while trying get the Angular application to work with our source. The code in question for us, is using a dynamic import to load an Angular module on the fly without using the router:

const lazyLoadDefinition = {
  loadChildren: (): Promise<any> => import('./lazy/some-angular.module').then((m) => m.SomeAngularModule)
};
...

  loadModuleRef(): Observable<NgModuleRef<NwAnyValue>> {
    if (!this.moduleObs) {
      this.moduleObs = this.nwLazyService.dynamicallyLoadModule(this.injector, lazyLoadDefinition).pipe(
        tap((moduleRef) => this.getServiceFromModule(moduleRef)),
        shareReplay(1)
      );
    }
    return this.moduleObs;
  }

This is producing the error:

Failed to load component Error: Dynamic require of "./some-angular.module-IFDBFVNQ.js" is not supported

Which is coming from:

var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
  if (typeof require !== "undefined")
    return require.apply(this, arguments);
  throw Error('Dynamic require of "' + x + '" is not supported');
});

I'm not sure if I need to change something in my tsconfig or I'm hitting this bug.

@angular-devkit/build-angular 17.2.0

@Moccod
Copy link

Moccod commented Mar 24, 2024

Experiencing same bug in 17.3

Angular CLI: 17.3.0
Node: 20.11.1
Package Manager: npm 10.2.4
OS: win32 x64

Angular: 17.3.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... platform-server, router, ssr

Package Version

@angular-devkit/architect 0.1703.0
@angular-devkit/build-angular 17.3.0
@angular-devkit/core 17.3.0
@angular-devkit/schematics 17.3.0
@schematics/angular 17.3.0
rxjs 7.8.1
typescript 5.3.3
zone.js 0.14.4`

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants