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 #27994

Closed
1 task done
danielalexis opened this issue Jul 3, 2024 · 2 comments
Closed
1 task done

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

danielalexis opened this issue Jul 3, 2024 · 2 comments

Comments

@danielalexis
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

No response

Description

This is the same as #26833. As others have pointed this out, it still doesnt work

Minimal Reproduction

Minimal reproduction on the related issue

Exception or Error

Uncaught Error: Dynamic require of "google-protobuf" is not supported

Your Environment

Angular CLI: 18.0.6
Node: 20.12.1
Package Manager: npm 10.8.1
OS: win32 x64

Angular: 18.0.5
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------      
@angular-devkit/architect       0.1800.6
@angular-devkit/build-angular   18.0.6
@angular-devkit/core            18.0.6
@angular-devkit/schematics      18.0.6
@angular/cli                    18.0.6
@schematics/angular             18.0.6
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.7

Anything else relevant?

No response

@alan-agius4
Copy link
Collaborator

This issue arises because parts of the application are written in CommonJS, as seen in this file.

During development, external dependencies are not bundled, causing the require statement to be transformed into a dynamic require.

There are two possible solutions to resolve this:

  1. Rewrite these files in ECMAScript Modules (ESM) since CommonJS (CJS) is intended for Node.js environments.

  2. Exclude google-protobuf from being prebundled, which will prevent the need for dynamic requires. Update your serve configuration in angular.json as follows:

"serve": {
  "executor": "@angular-devkit/build-angular:dev-server",
  "options": {
    "prebundle": {
      "exclude": [
        "google-protobuf",
        "google-protobuf/google/protobuf/any_pb.js"
      ]
    }
  }
}

By implementing one of these solutions, you can address the issue of dynamic requires during development.

@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 Aug 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants