question: Angular Warning: CommonJS or AMD dependencies can cause optimization bailouts.
See original GitHub issueUpon 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:
- Created 3 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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:
This fixed the issue.
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 thisimport isDivisibleByValidator from 'validator/es/lib/isDivisibleBy';Then the WARNING should go away and projects using class-validator will be able to get optimized better.