question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question: Angular Warning: CommonJS or AMD dependencies can cause optimization bailouts.

See original GitHub issue

Upon adding class-validator to my Angular project, I get this warning when building:

WARNING in /node_modules/class-validator/esm2015/decorator/common/IsLatLong.js depends on 'validator'. CommonJS or AMD dependencies can cause optimization bailouts.

I am not using the @IsLatLong() decorator so I’m assuming the tree shaking/webpack will ignore this, but I just wanted to put a question out there for reassurance!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mcelotticommented, Jan 25, 2021

I had the same problem and, according to https://angular.io/guide/build#configuring-commonjs-dependencies, I added “validator” to “allowedCommonJsDependencies” inside my “angular.json” file:

            "allowedCommonJsDependencies": [
              "validator"
            ]

This fixed the issue.

2reactions
ThorstenKunzcommented, Jan 12, 2021

I will go forward and close this as we have nothing to fix this.

I don’t think this is correct. According to validator.js github site they do provide tree-shakeable ES imports. You have to replace the import paths a little bit:

import isDivisibleByValidator from 'validator/lib/isDivisibleBy'; with this import isDivisibleByValidator from 'validator/es/lib/isDivisibleBy';

Then the WARNING should go away and projects using class-validator will be able to get optimized better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading to Angular 10 - Fix CommonJS or AMD ...
CommonJS or AMD dependencies can cause optimization bailouts. By importing from the root module instead, the warning is no longer present ...
Read more >
Angular warning: CommonJS or AMD dependencies can ...
However the Angular warning displays with the following message: Warning: ... CommonJS or AMD dependencies can cause optimization bailouts.
Read more >
CommonJS or AMD dependencies can cause optimization ...
CommonJS or AMD dependencies can cause optimization bailouts. depends on 'highcharts/modules/gantt'. CommonJS or AMD dependencies can cause ...
Read more >
Fix CommonJS or AMD dependencies can cause optimization ...
JavaScript : Upgrading to Angular 10 - Fix CommonJS or AMD dependencies can cause optimization bailouts [ Gift : Animated Search Engine ...
Read more >
Angular 10 Upgrade - Fix CommonJS or AMD dependencies ...
JavaScript : Angular 10 Upgrade - Fix CommonJS or AMD dependencies can cause optimization bailouts [ Gift : Animated Search Engine ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found