-
Notifications
You must be signed in to change notification settings - Fork 12k
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
No apparent way to use --bundle-dependencies=all
successfully since 1.5.0
#8616
Comments
@filipesilva any thoughts on this? |
@Brocco can you take a look please? |
@Brocco did you get a chance to look into this? |
Really love to have this nailed down. Thanks guys. |
Ok I think the issue is with the uglifyjs plugin. It seems that angular cli is using To confirm this, I first build bundle using below command:
Then I used
(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
when I used this bundle it threw the error @SteveSandersonMS mentioned above.
|
@filipesilva can you please share if there is any update on this? |
Personally I would love to have this feature available as soon as possible, but for now I have stopped wasting time and effort on making angular apps universal. |
+1 |
seems still not working with the latest release. Does anyone have an alternative for this? My CI/CD pipeline is taking 30+ minutes to complete due to this issue and #6795. |
@SteveSandersonMS If you change this line in package.json
with this
everything works. I'm not sure what's different between "--prod" and "--build-optimizer --aot --environment prod", but I think they're almost the same. Also, it's only necessary for the server-side version of the code so if some random optimization is missing it might be okay. |
@filipesilva @hansl @Brocco can you please share if there is any update on this? |
@speige can you please compare the size of the bundles with --prod and --build-optimizer --aot --environment prod ? |
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. |
Fyi, I've also tried this on Angular 6 RC & the same issue still exists. The format of angular-cli.json has changed, but the issue & workaround are still the same. broken:
working:
Only difference is optimization: true/false. Without bundleDependencies, both true/false work, with bundleDepencencies: all only optimization: false works. Also, same error during ng serve (Right-hand side of 'instanceof' is not an object) & same yellow circular dependency warning occur [which I'm ignoring, since it still works]. Although if I remember correctly the yellow warning was about the express/view.js file instead of core.umd.js but that may be because I was on a completely different repo, not Steve's angular-bundledependencies-repro |
@hansl @filipesilva what if we update the Uglify settings to preserve the class names for server builds? I believe this would be a better solution than to turn mangle off. What do you think? |
@filipesilva @hansl did you get a chance to check my last comment of Jun 10? |
This is a huge issue because lots of people wants to use Angular Universal with ASP.NET Core backend. Could you please prioritize this to the top? |
I've tried every suggestion in this thread, but still run into this issue:
|
We have a fix to the ng add schematics for 8.0 for this.(PR above) But to manually fix your existing project - Move all Angular related imports in server.ts as re-exports in main.server.ts and then you can use --bundleDependencies all. Would also need to change the top-level webpackconfig to main.ts external to server.ts builds. Shown in example repo here - With this you should need to deploy only dist/server.js and dist/server/main.js and not node_modules. |
@dominikfoldi @stefankip - can you try the suggestion above? |
@vikerman our Angular project is not ejected so I cannot modify the webpack.config. I can wait until Angular 8. Glad to hear that you have a fix! |
@dominikfoldi - Not sure what your setup is. But essentially the fix would be to move all references to @angular and @nguniversal to the main.server.ts and bundle it once there and use only re-exports from the express(or whichever) entry point. Otherwise you would end up with two copies of Angular and things will start to fail randomly. |
@vikerman
Like already said in this issue disabling optimization fixes this. Again thx for your effort & the example repo |
@vikerman awesome, works perfectly! Thank you very much! |
Closing this as we have some reports that this works. |
@vikerman I think the issue still exists
|
@vikerman how about this #8616 (comment) ? |
Ok I have found one solution.
Please do share feedback and suggestions for further improvements. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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
Repro steps
--bundle-dependencies=all
could work (but still doesn't).npm install
npm run build:ssr
thennpm run serve:ssr
. If you visit http://localhost:4000, you'll get both server and client rendering.npm run build:ssr:prod
thennpm run serve:ssr
), then it does not work - you'll get this error:If you trace this into the
server.js
bundle code, what's happening is that it's testing whethersomeValue 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, becauseHTMLElement
isundefined
. So the generated bundle isn't going to work for SSR under Node.--bundle-dependencies=all
from lines 22 and 23 inpackage.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 theirnode_modules
to production, and attempting to publish 20,000+ files fromnode_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.The text was updated successfully, but these errors were encountered: