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

6.0.0 build fails with lazy modules and Node API #10698

Closed
Enngage opened this issue May 7, 2018 · 6 comments
Closed

6.0.0 build fails with lazy modules and Node API #10698

Enngage opened this issue May 7, 2018 · 6 comments

Comments

@Enngage
Copy link

Enngage commented May 7, 2018

Versions

Angular CLI: 6.0.0
Node: 8.9.4
OS: win32 x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

Observed behavior

We have application that lazy loads module that depends on node Api and is included only if process is running under node using:

 if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
      // require module with Node Api
      const adapter = require('./moduleWithNodeApi');    
}

We confirmed that this branch is not hit when building the Angular application and its also not hit when running ng serve. For some reasons, however, the builder seems to be attempting to resolve the module anyway. Because of that we get this error during compilation:

ERROR in ./node_modules/parse5/lib/parser/parser_stream.js
Module not found: Error: Can't resolve 'stream' in 'c:\dev\parse5test\node_modules\parse5\lib\parser'
ERROR in ./node_modules/parse5/lib/sax/index.js
Module not found: Error: Can't resolve 'stream' in 'c:\dev\parse5test\node_modules\parse5\lib\sax'
ERROR in ./node_modules/parse5/lib/sax/dev_null_stream.js
Module not found: Error: Can't resolve 'stream' in 'c:\dev\parse5test\node_modules\parse5\lib\sax'
ERROR in ./node_modules/parse5/lib/serializer/serializer_stream.js
Module not found: Error: Can't resolve 'stream' in 'c:\dev\parse5test\node_modules\parse5\lib\serializer'

Sure, we could use parse5 on version 4 (which does have 'sort of' workaround for running under node), but then we get a warning message like:

WARNING in ./node_modules/parse5/lib/index.js
55:23-49 Critical dependency: the request of a dependency is an expression

We know we can skip this in webpack.config (and we did), but it seems to not be relevant to the issue I'm raising. I would expect that lazy modules would not be resolved during compilation. They can fail during runtime, thats fine (though it should not happen because we include different modules in different environments).

This worked perfectly fine with angular/cli@1.7.3

Desired behavior

Don't resolve lazy loaded modules with require when building an app because these modules might contain API that does not exist in given environment.

@Shak3y
Copy link

Shak3y commented May 7, 2018

I'm running into this issue as well. @Enngage did you have a workaround for now?

@Enngage
Copy link
Author

Enngage commented May 9, 2018

@Shak3y I don't unfortunately. It seems like Angular/WebPack is doing static analysis and is resolving require in whatever condition it is under.

@slawiko
Copy link

slawiko commented Jul 9, 2018

@Enngage any updates? Today I saw same issue in my project. But it become happens only after trying to switch on yarn workspaces. Maybe it can be a clue

@Enngage
Copy link
Author

Enngage commented Jul 9, 2018

Seems like this is bug in angular-cli.. Would love to see this resolved. As a workaround we have created a separated package with webpack where we excluded files with node dependency (they are not in project = there is no problem). If you are using external libraries that have this problem, you are in troubles.

@ngbot ngbot bot added this to the needsTriage milestone Jan 24, 2019
@filipesilva
Copy link
Contributor

We have indeed removed the native node APIs in v6. You can find more information about this in #9827 (comment).

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

No branches or pull requests

5 participants