Skip to content

Universal --bundle-dependencies=all works with --aot but fails with --prod #8900

Closed

Description

@naveedahmed1

Versions

Angular CLI: 1.6.0
Node: 8.9.1
OS: win32 x64
Angular: 5.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

@angular/cdk: 5.0.1
@angular/cli: 1.6.0
@angular/flex-layout: 2.0.0-beta.11-b01c2d7
@angular/material: 5.0.1
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.40
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0
@schematics/angular: 0.1.10
@schematics/schematics: 0.0.10
typescript: 2.4.2
webpack: 3.10.0

Repro steps

When using below command it works perfectly.

ng build -- --app=ssr --output-hashing=media --aot --bundle-dependencies=all

But when we run below command:

ng build -- --app=ssr --output-hashing=media --prod --bundle-dependencies=all

It throws below warnings:

WARNING in ./node_modules/@angular/core/bundles/core.umd.js
6579:23-44 Critical dependency: the request of a dependency is an expression
    at ImportLazyContextDependency.getWarnings (D:\MyProject\ClientApp\node_modules\webpack\lib\dependencies\ContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:703:24)
    at Compilation.finish (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:561:9)
    at applyPluginsParallel.err (D:\MyProject\ClientApp\node_modules\webpack\lib\Compiler.js:502:17)
    at D:\MyProject\ClientApp\node_modules\tapable\lib\Tapable.js:289:11
    at _addModuleChain (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:507:11)
    at processModuleDependencies.err (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:477:14)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
 @ ./node_modules/@angular/core/bundles/core.umd.js
 @ ./src/main.server.ts
 @ multi ./src/main.server.ts

WARNING in ./node_modules/@angular/core/bundles/core.umd.js
6599:23-110 Critical dependency: the request of a dependency is an expression
    at ImportLazyContextDependency.getWarnings (D:\MyProject\ClientApp\node_modules\webpack\lib\dependencies\ContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:703:24)
    at Compilation.finish (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:561:9)
    at applyPluginsParallel.err (D:\MyProject\ClientApp\node_modules\webpack\lib\Compiler.js:502:17)
    at D:\MyProject\ClientApp\node_modules\tapable\lib\Tapable.js:289:11
    at _addModuleChain (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:507:11)
    at processModuleDependencies.err (D:\MyProject\ClientApp\node_modules\webpack\lib\Compilation.js:477:14)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
 @ ./node_modules/@angular/core/bundles/core.umd.js
 @ ./src/main.server.ts
 @ multi ./src/main.server.ts

And when we run the app it shows below error in log:

 StaticInjectorError[InjectionToken DocumentToken]: 
  StaticInjectorError[InjectionToken DocumentToken]: 
    Right-hand side of 'instanceof' is not an object

Activity

  1. hansl commented on Dec 19, 2017

    @hansl
    Contributor

    Hi @naveedahmed1

    Could you try with --build-optimizer=false? Also, we need a reproduction here. That doesn't look like a new application (or perhaps it is?).

  2. naveedahmed1 commented on Dec 20, 2017

    @naveedahmed1
    Author

    Thank you so much @hansl

    It seems that --build-optimizer=false doesnt make any difference and show same warning.

    To reproduce, you can use the universal starter repo https://github.com/angular/universal-starter and run the below command:

    ng build --app=1 --output-hashing=media --prod --bundle-dependencies=all

  3. naveedahmed1 commented on Dec 27, 2017

    @naveedahmed1
    Author

    Just to add the issue still exists in v 1.6.3

  4. naveedahmed1 commented on Dec 27, 2017

    @naveedahmed1
    Author

    Probably its the reason why server bundles aren't working with --bundle-dependencies=all and throwing below error in log:

    An unhandled exception has occurred: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
      StaticInjectorError(Platform: core)[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
        Right-hand side of 'instanceof' is not an object
          TypeError: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
      StaticInjectorError(Platform: core)[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
        Right-hand side of 'instanceof' is not an object
        at Re (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2659372)
        at Se (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2659249)
        at dn (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2682010)
        at _l.insertToken (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2702976)
        at C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2661904
        at Fe (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2661919)
        at A (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2657217)
        at Object.parse (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2701906)
        at Object.t.createDocument (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:4257849)
        at Object.t.createWindow (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:4257953)
    Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
      StaticInjectorError(Platform: core)[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
        Right-hand side of 'instanceof' is not an object
    TypeError: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
      StaticInjectorError(Platform: core)[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
        Right-hand side of 'instanceof' is not an object
        at Re (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2659372)
        at Se (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2659249)
        at dn (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2682010)
        at _l.insertToken (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2702976)
        at C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2661904
        at Fe (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2661919)
        at A (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2657217)
        at Object.parse (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:2701906)
        at Object.t.createDocument (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:4257849)
        at Object.t.createWindow (C:\inetpub\wwwroot\ClientApp\dist-server\main.bundle.js:1:4257953)
       at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.<InvokeExportAsync>d__7`1.MoveNext()
    
  5. naveedahmed1 commented on Jan 3, 2018

    @naveedahmed1
    Author

    @Brocco can you please confirm if you were able to reproduce this issue?

  6. naveedahmed1 commented on Jan 5, 2018

    @naveedahmed1
    Author

    Ok I think the issue is with the uglifyjs plugin. It seems that angular cli is using --compress and --mangle option with this plugin for server bundles and its causing the issue.

    To confirm this, I first build bundle using below command:

    ng build --app=ssr --output-hashing=media --aot --bundle-dependencies=all

    Then I used uglifyjs using below command

    uglifyjs main.bundle.js --output output.js

    (main.bundle.js is the server bundle generated in 1st command)

    the bundle generated after above command worked perfectly.

    Then I tried generating a bundle with --compress and --mangle

    uglifyjs main.bundle.js --output output.js --compress --mangle

    when I used this bundle it threw the error I mentioned in my 2nd last comment.

    An unhandled exception has occurred: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
      StaticInjectorError(Platform: core)[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
        Right-hand side of 'instanceof' is not an object
          TypeError: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
     
    
  7. added
    freq1: lowOnly reported by a handful of users who observe it rarely
    and removed
    needs: repro stepsWe cannot reproduce the issue with the information given
    on Feb 1, 2018
  8. 24 remaining items

  9. speige commented on Sep 27, 2018

    @speige

    I agree that the deployment issue is caused by visual studio's publish. That's why I'd suggest not deploying node_modules through visual studio & instead doing npm install on the server. I haven't personally tried it, but it seems plausible that it'd work.

  10. naveedahmed1 commented on Sep 27, 2018

    @naveedahmed1
    Author

    I doubt if its supported on Windows IIS web server. May be that would work when you have root access of the server, login using remote desktop and then run npm install on that specific site directory with admin permissions.

  11. speige commented on Sep 27, 2018

    @speige

    It could probably also be done remotely through powershell.

  12. naveedahmed1 commented on Sep 27, 2018

    @naveedahmed1
    Author

    I am not sure about it, but I think that would still require elevated permissions.

  13. speige commented on Sep 27, 2018

    @speige

    True. Elevated permissions would probably be required. I didn't realize this would be an issue, because I wasn't thinking about support for shared web hosts.

    I assume the linux+node/express setup also requires running npm install on the server.

    Maybe if you're on a shared web host (or don't have elevated permissions) you shouldn't be doing Universal/SSR ?

  14. naveedahmed1 commented on Sep 27, 2018

    @naveedahmed1
    Author

    No I am not talking about shared host but for website deployment you shouldn't be requiring elevated permissions a simple access through ftp account should be sufficient.

  15. speige commented on Sep 27, 2018

    @speige

    You're logging a bug because you don't want to type your password?

    If there's a valid workaround, let's move on & let them work on more important stuff like Angular v7 & ivy.

    I'll drop out of this conversation now. Not trying to start a flaming war & I don't have anything else useful to contribute. But, the issue feels unnecessary to me.

  16. added
    needs: discussionOn the agenda for team meeting to determine next steps
    on Jan 10, 2019
  17. added this to the Backlog milestone on Jan 10, 2019
  18. alan-agius4 commented on Sep 2, 2019

    @alan-agius4
    Collaborator

    Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

    If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

  19. angular-automatic-lock-bot commented on Oct 3, 2019

    @angular-automatic-lock-bot

    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.

  20. locked and limited conversation to collaborators on Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions