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

Improve automatic tree-shaking #1739

Closed
hfournier opened this issue Sep 27, 2021 · 1 comment
Closed

Improve automatic tree-shaking #1739

hfournier opened this issue Sep 27, 2021 · 1 comment
Labels

Comments

@hfournier
Copy link

Describe the bug
When building an Angular project that uses class-validator, Angular generates a large number of warnings regarding CommonJS dependencies.

As you can see in the example below, I can simply import from class-validator without explicitly having to specify class-validator/esm2015.

import { IsEmail } from 'class-validator';

The bundling will automatically use \node_modules\class-validator\esm2015.
However, it is not automatically using \node_modules\validator\es, which results in all the warnings (see below).

A solution is suggested by @NoNameProvided in this thread.

Examples

Warning: C:\Users\Me\Documents\MyProject\node_modules\class-validator\esm2015\decorator\string\IsEmail.js depends on 'validator/lib/isEmail'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

The above warning is generated for every validator, whether it's used or not.

Additional context
Validator.js version: 13.6.0
Node.js version:
OS platform: windows 10

Angular CLI: 12.2.7
Node: 14.17.0
Package Manager: npm 6.14.7
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1202.7
@angular-devkit/build-angular   12.2.7
@angular-devkit/core            12.2.7
@angular-devkit/schematics      12.2.7
@schematics/angular             12.2.7
rxjs                            6.5.5
typescript                      4.3.5
@tux-tn
Copy link
Member

tux-tn commented Sep 30, 2021

Thank you for your suggestion @hfournier

We are already discussing this in #683 , please use that issue if you have any addition concerning tree-shaking/es6 imports.

@tux-tn tux-tn closed this as completed Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants