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

Error in SSR if server build with bundleDependencies=all #12273

Closed
clark0x opened this issue Sep 14, 2018 · 19 comments
Closed

Error in SSR if server build with bundleDependencies=all #12273

clark0x opened this issue Sep 14, 2018 · 19 comments
Assignees
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@clark0x
Copy link

clark0x commented Sep 14, 2018

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [x] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Angular CLI: 6.2.1
Node: 8.11.2
OS: darwin x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package Version

@angular-devkit/architect 0.8.1
@angular-devkit/build-angular 0.8.1
@angular-devkit/build-ng-packagr 0.8.1
@angular-devkit/build-optimizer 0.8.1
@angular-devkit/build-webpack 0.8.1
@angular-devkit/core 0.8.1
@angular-devkit/schematics 0.8.1
@angular/cdk 6.4.7
@angular/cli 6.2.1
@angular/flex-layout 6.0.0-beta.18
@angular/material 6.4.7
@angular/pwa 0.8.1
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.2.1
@schematics/angular 0.8.1
@schematics/update 0.8.1
ng-packagr 4.1.1
rxjs 6.3.2
typescript 2.9.2
webpack 4.18.0

Repro steps

I use universal-starter, only change one line in angular.json:

"server": {
  "configurations": {
    "production": {
      "bundleDependencies": "all", <= added
      ...
$ git clone -b issue-error-with-bundleDependencies  git@github.com:clarkorz/universal-starter.git
$ cd universal-starter
$ yarn install
$ yarn build:ssr
$ yarn serve:ssr

Access http://localhost:4000 in browser.

The log given by the failure

Error: No NgModule metadata found for '[object Object]'.
    at NgModuleResolver.resolve (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@angular/compiler/bundles/compiler.umd.js:11962:27)
    at CompileMetadataResolver.getNgModuleMetadata (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@angular/compiler/bundles/compiler.umd.js:10604:47)
    at JitCompiler._loadModules (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@angular/compiler/bundles/compiler.umd.js:23914:55)
    at JitCompiler._compileModuleAndComponents (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@angular/compiler/bundles/compiler.umd.js:23895:40)
    at JitCompiler.compileModuleAsync (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@angular/compiler/bundles/compiler.umd.js:23855:41)
    at CompilerImpl.compileModuleAsync (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js:195:35)
    at /Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@nguniversal/express-engine/bundles/express-engine.umd.js:95:25
    at new ZoneAwarePromise (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/zone.js/dist/zone-node.js:891:29)
    at getFactory (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@nguniversal/express-engine/bundles/express-engine.umd.js:81:12)
    at View.engine (/Users/wangshuo/Documents/GitHub/universal-starter/node_modules/@nguniversal/express-engine/bundles/express-engine.umd.js:60:13)

Desired functionality

bundleDependencies=all should work as same as bundleDependencies=none.

Mention any other details that might be useful

No.

@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely workaround1: obvious area: devkit/build-angular labels Sep 14, 2018
@ngbot ngbot bot added this to the needsTriage milestone Sep 14, 2018
@alan-agius4
Copy link
Collaborator

I think what's happening here, is that you have 2 instances of Angular providers running in parallel.

One in the server.bundle javascript files since it's being bundled and another which is being required from the server.js

//cc @vikerman

@naveedahmed1
Copy link

Is it related to #8616 ?

@hansl
Copy link
Contributor

hansl commented Sep 28, 2018

It seems it is a duplicate of #8616.

@vikerman
Copy link
Contributor

vikerman commented Sep 28, 2018

Have a repro. First need to figure out why JitCompiler is getting involved at all since we pass in the NgFactory to the express engine.

@NateWarner
Copy link

@vikerman Any update on this issue or workaround? I'm running into it with latest Angular CLI and this seems to be a hard blocker atm.

@ErazerBrecht
Copy link

I'm running against the same problems.
The workaround of #8616 also didn't seem to work (optimization: false)

@mgechev
Copy link
Member

mgechev commented Jan 25, 2019

@vikerman @MarkPieszak, would you have a look?

@naveedahmed1
Copy link

@mgechev its related to #8616 which was opened on Nov 23, 2017 but still not fixed.

@vikerman
Copy link
Contributor

vikerman commented Jan 31, 2019

On it (again). Investigating the root cause.

@ErazerBrecht
Copy link

ErazerBrecht commented Apr 7, 2019

@vikerman
Hello,
I don't want to be annoying but did you make any progress?

I'm at a point where we really need it. So my plan was to bundle it myself with webpack.
So I could avoid the bundleDependencies=all. But ofcourse this also causes the same problem.

No NgModule metadata found for '[object Object]'.

I tried to debug it a bit, but I'm not knowable of the internal workings of Angular itself.
So I have no clue where to start. And after searching the net I stumbled on this issue 'again'.

@ErazerBrecht
Copy link

@vikerman
I tried to debug some stuff.
And I'm probably already going to say stuff you already know.

https://github.com/angular/universal/blob/83f659777a1f7914c357d5c0eb72705b04dc94ea/modules/express-engine/src/main.ts#L118

When using bundleDependencies=all this check returns false.
I have no idea why. When enabling or disabling bundleDependencies the result of
Object.getPrototypeOf(moduleOrFactory) seemed to be the 'same'.

I removed the check locally to see if it would magically work. But it seems we then have a whole bunch of other errors. So I assume the generated webpack bundle is 'wrong'. My knowledge of webpack is also to limited to say something useful (I tried to compare the bundles, but I couldn't really make much of it)

@vikerman
Copy link
Contributor

vikerman commented May 24, 2019

We were ending up with two copies of Angular due to the bundling setup we have for express-engine. We think we finally have a solution(See PR above) and turning on bundleDependencies on by default for version 8.0 of @nguniversal/express-engine. Still end up with a dist/server.js and dist/server/main.js (and dist/server/*.js for dynamic import based lazy routes) - But that's still lot better than shipping entire node_modules.

@vikerman
Copy link
Contributor

@ErazerBrecht - We think we have a solution for version 8.0.

@ErazerBrecht
Copy link

@vikerman
I saw the PR ;)
I'm very exited to test it out.

Thx for update!
Enjoy your weekend!

@everflux
Copy link

everflux commented Aug 2, 2019

Was this fixed with 8.2 ?

@vikerman
Copy link
Contributor

The new 8.x versions of @nguniversal/express-engine schematics creates a setup which avoid this issue.

If you are upgrading to 8.x version please follow https://github.com/angular/universal/blob/master/docs/v8-upgrade-guide.md

@naveedahmed1
Copy link

Would it work with ASP. Net/.Net Core? Can you please add instructions for that in readme docs?

@alan-agius4
Copy link
Collaborator

@naveedahmed1, yeah this should also work for the .net implementation. You’d need to export ngAspnetCoreEngine from main.server.ts.

Closing this issue as it should be solved as per @vikerman’s comment.

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.

@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 Oct 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

No branches or pull requests

10 participants