LoginSignup
3
2

More than 1 year has passed since last update.

ng build時のCommonJS or AMD dependencies can cause optimization bailoutsの対処法

Last updated at Posted at 2021-06-30

現象

npm installでモジュールを追加すると下記警告がビルド時に発生しました。

Warning: {tsファイル名} depends on '{nodeパッケージ名}'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

この警告を放置しておくと、ビルド成果物のサイズが不必要に大きくなってしまうようです。

対処法

angular.jsonの"build"→"options配下にallowedCommonJsDependenciesの設定を追加します。仮にnpmでhogeというパッケージがこの警告に引っ掛かっている場合は下記のような記述をします。

angular.json
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": [
              "hoge"
            ],
            ...


3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2