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.

No apparent way to use `--bundle-dependencies=all` successfully since 1.5.0

See original GitHub issue

Prior to the 1.5.0 release, it was possible to pass --bundle-dependencies=all --prod to get an AoT compiled self-contained bundle that worked for server-side rendering (SSR) under Node.js. Since 1.5.0, these flags produce a bundle that, as far as I can tell, can never work because they now rely on the existence of browser DOM APIs that don’t exist in Node.

If there is any way to use --bundle-dependencies=all successfully in --prod build with 1.5.0+, I’d love to know about it.

Versions

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

@angular/cli: 1.5.4
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.21
@angular-devkit/schematics: 0.0.37
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.4
@schematics/angular: 0.1.7
typescript: 2.4.2
webpack: 3.8.1

Repro steps

  • Clone the example repo at https://github.com/SteveSandersonMS/angular-bundledependencies-repro. This is the same as the universal-starter repo, except for one commit that gets as close as I can to a scenario where --bundle-dependencies=all could work (but still doesn’t).
  • Run npm install
  • Observe that it works fine in a non-prod build by running npm run build:ssr then npm run serve:ssr. If you visit http://localhost:4000, you’ll get both server and client rendering.
  • Observe that if you build in prod mode (run npm run build:ssr:prod then npm run serve:ssr), then it does not work - you’ll get this error:
TypeError: StaticInjectorError[InjectionToken DocumentToken]: 
  StaticInjectorError[InjectionToken DocumentToken]: 
    Right-hand side of 'instanceof' is not an object
    at ke (C:\path\angular-bundledependencies-repro\dist\server.js:4106:724114)
    at xe (C:\path\angular-bundledependencies-repro\dist\server.js:4106:723991)
    at lr (C:\path\angular-bundledependencies-repro\dist\server.js:4106:746752)
    at _n.insertToken (C:\path\angular-bundledependencies-repro\dist\server.js:4106:767718)
    at C:\path\angular-bundledependencies-repro\dist\server.js:4106:726646
    at Fe (C:\path\angular-bundledependencies-repro\dist\server.js:4106:726661)
    at I (C:\path\angular-bundledependencies-repro\dist\server.js:4106:721959)
    at Object.parse (C:\path\angular-bundledependencies-repro\dist\server.js:4106:766648)
    at Object.t.createDocument (C:\path\angular-bundledependencies-repro\dist\server.js:4106:1194422)
    at Object.t.createWindow (C:\path\angular-bundledependencies-repro\dist\server.js:4106:1194526)

If you trace this into the server.js bundle code, what’s happening is that it’s testing whether someValue instanceof HTMLElement (though it’s not obvious at first glance because everything is minified and renamed). That code would be OK in a browser, but it’s an error in Node, because HTMLElement is undefined. So the generated bundle isn’t going to work for SSR under Node.

  • If you want, verify that removing --bundle-dependencies=all from lines 22 and 23 in package.json is enough to make it work in both dev and prod builds. So the problem is the combination of --prod with --bundle-dependencies=all - you can use either on their own, but not both together.

Observed behavior

Fails with the Right-hand side of 'instanceof' is not an object error shown above.

Desired behavior

SSR works as it did in the non-prod build.

Mention any other details that might be useful (optional)

The equivalent did work pre-1.5.0 (which was also Angular 4.x).

The reason I’m asking about this is because I’m building new Angular CLI-based ASP.NET templates that will be included in the .NET Core SDK and Visual Studio. We want the template to use --bundle-dependencies=all by default because then developers don’t have to publish their node_modules to production, and attempting to publish 20,000+ files from node_modules is extremely time-consuming (and not always reliable) from VS. Plus it tends to hit Windows path-length limitations depending on the deployment target.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:25
  • Comments:44 (8 by maintainers)

github_iconTop GitHub Comments

9reactions
naveedahmed1commented, Feb 9, 2018

@hansl should we expect this and https://github.com/angular/angular-cli/issues/8900 to be solved in V6? If this could be fixed, it would really help developers using Angular and SSR with Windows technologies (.net core) or hosting Angular apps on Windows servers/IIS/Kestrel.

8reactions
naveedahmed1commented, Apr 9, 2018

Thanks for sharing this, I believe the size of the bundle should have an effect on the memory consumption on server as well for heavy traffic websites. For developers using .net technologies, this requires immediate attention from Angular CLI team, its already been ~5 months.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use bundleDependencies (to avoid unpublish blues)
When Azer Koçulu happily unpublished his npm packages (https://twitter.com/azerbike/status/712407356760403968) it kind of broke the internet ...
Read more >
node_modules/eslint-plugin-import/CHANGELOG.md - PLMlab
Added no-internal-modules rule: restrict deep package imports to specific folders. (#485, thanks @spalger!) extensions : allow override of a ...
Read more >
npm Documentation - API Manual
Run the code using node index.js . It should output [2, 3] . If you had not properly installed lodash , you would...
Read more >
Changelog | Addressables | 1.19.19
Fix issue where opening the Analyze window logs null exceptions after running the "Check Duplicate Bundle Dependencies" rule. Add platform type to ""Use...
Read more >
npm/CHANGELOG.md - UNPKG
196, Good to see you all again! It's been a while since we had an LTS release, and. 197, the team continues to...
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