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

bug(commonjs): erroneous ngfactory #7910

Closed
CaerusKaru opened this issue Oct 3, 2017 · 19 comments
Closed

bug(commonjs): erroneous ngfactory #7910

CaerusKaru opened this issue Oct 3, 2017 · 19 comments
Assignees
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken
Milestone

Comments

@CaerusKaru
Copy link
Member

CaerusKaru commented Oct 3, 2017

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request

Versions.

@angular/cli: 1.5.0-beta.2
node: 8.6.0
os: darwin x64
@angular/animations: 5.0.0-rc.0
@angular/cdk: 2.0.0-beta.11
@angular/common: 5.0.0-rc.0
@angular/compiler: 5.0.0-rc.0
@angular/core: 5.0.0-rc.0
@angular/forms: 5.0.0-rc.0
@angular/http: 5.0.0-rc.0
@angular/material: 2.0.0-beta.11
@angular/platform-browser: 5.0.0-rc.0
@angular/platform-browser-dynamic: 5.0.0-rc.0
@angular/platform-server: 5.0.0-rc.0
@angular/router: 5.0.0-rc.0
@angular/cli: 1.5.0-beta.2
@angular/compiler-cli: 5.0.0-rc.0
@angular/language-service: 5.0.0-rc.0
typescript: 2.5.3

Repro steps.

  1. Clone the sample repo found here
  2. Change into the cli directory
  3. Run npm install and npm run build:dynamic

To show the second type of error (detailed below):

  1. After the steps above, remove MatCardModule from app.module.ts, and remove the reference to <mat-card> in app.component.ts.
  2. Run npm run build:dynamic && npm run serve:dynamic (which should succeed this time)
  3. Navigate to localhost:4000. Disable JavaScript and reload the page
  4. Attempt to navigate to the lazy route, examine the server for the error log

To show the third type of error (detailed below):

  1. Re-enable JavaScript on localhost:4000 and reload the page
  2. Attempt to navigate to the lazy route, examine the browser console for the error log

The log given by the failure.

ERROR in ./dist/server/main.bundle.js
Module not found: Error: Can't resolve '@angular/material/card/typings/index.ngfactory' in '/Users/main/universal-cli-bug/cli/dist/server'
 @ ./dist/server/main.bundle.js 1:2433-2490
 @ ./prerender.ts

Desired functionality.

AOT compilation needs to work for commonjs bundling where the bundle includes a lazy-loaded module that also includes an external module like Angular Material.

Mention any other details that might be useful.

This is an issue only when the external module is included in a lazy-loaded module. If it's included at the top-level, it works as expected. It also works as expected in [email protected]

@Brocco Brocco added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken labels Oct 3, 2017
@CaerusKaru
Copy link
Member Author

@filipesilva Is there any update on this issue? I feel like 1.5.0 is nearing final and there has been no progress made here.

To add on to symptoms of this issue, adding the bundle-dependencies flag results in a different error:

Error: No NgModule metadata found for '[object Object]'. This error occurs when the server spins up and tries to compile the module with JIT

When running without the flag, the bundle size for the main module is also significantly smaller than it should be (which makes sense, since most of the lazy-loaded content isn't being compiled).

cc @hansl for bundle-dependencies issue

@filipesilva filipesilva assigned Brocco and unassigned filipesilva Oct 24, 2017
@filipesilva
Copy link
Contributor

@CaerusKaru do you think this is related to #7901 perhaps? It also had to do with lazy modules and #8157 fixed it.

@Brocco can you have a look?

@CaerusKaru
Copy link
Member Author

@filipesilva It's unrelated, the issue persists in RC.3

@Brocco Here's the updated rub, as far as my investigations have gone:

  1. The error no longer surfaces during bundling when the module in question is lazy-loaded, but it does surface now when the module is imported at the top level (I've updated the repo above to reflect this)
  2. If the top-level import is removed, the build succeeds, but navigating to the lazy-loaded page with the module returns the following error:
TypeError: factory.create is not a function
    at MapSubscriber.project (/Users/main/universal-cli-bug/cli/dist/server.js:132272:51)
    at MapSubscriber._next (/Users/main/universal-cli-bug/cli/dist/server.js:135287:35)
    at MapSubscriber.Subscriber.next (/Users/main/universal-cli-bug/cli/dist/server.js:26375:18)
    at /Users/main/universal-cli-bug/cli/dist/server.js:109872:36
    at ZoneDelegate.invoke (/Users/main/universal-cli-bug/cli/dist/server.js:123046:26)
    at Object.onInvoke (/Users/main/universal-cli-bug/cli/dist/server.js:5080:33)
    at ZoneDelegate.invoke (/Users/main/universal-cli-bug/cli/dist/server.js:123045:32)
    at Zone.run (/Users/main/universal-cli-bug/cli/dist/server.js:122796:43)
    at /Users/main/universal-cli-bug/cli/dist/server.js:123527:57
    at ZoneDelegate.invokeTask (/Users/main/universal-cli-bug/cli/dist/server.js:123079:31)
    at resolvePromise (/Users/main/universal-cli-bug/cli/dist/server.js:123478:31)
    at resolvePromise (/Users/main/universal-cli-bug/cli/dist/server.js:123449:17)
    at /Users/main/universal-cli-bug/cli/dist/server.js:123527:17
    at ZoneDelegate.invokeTask (/Users/main/universal-cli-bug/cli/dist/server.js:123079:31)
    at Object.onInvokeTask (/Users/main/universal-cli-bug/cli/dist/server.js:5071:33)
    at ZoneDelegate.invokeTask (/Users/main/universal-cli-bug/cli/dist/server.js:123078:36)
    at Zone.runTask (/Users/main/universal-cli-bug/cli/dist/server.js:122846:47)
    at drainMicroTaskQueue (/Users/main/universal-cli-bug/cli/dist/server.js:123256:35)
    at ZoneTask.invokeTask (/Users/main/universal-cli-bug/cli/dist/server.js:123157:21)
    at Server.ZoneTask.invoke (/Users/main/universal-cli-bug/cli/dist/server.js:123142:48)

I'm hoping this is a simple module resolution issue, because it's incredibly frustrating.

@filipesilva
Copy link
Contributor

@MarkPieszak @Toxicable do you have any insight maybe?

@hansl
Copy link
Contributor

hansl commented Oct 25, 2017

Some sub issues should be fixed with #8188

@MarkPieszak
Copy link
Member

I haven't seen this one yet, but i'll take a look!

@CaerusKaru
Copy link
Member Author

CaerusKaru commented Oct 26, 2017

@hansl I installed cli-builds with #8188, but now the build doesn't respect tsconfig paths specified as follows:

"paths": {
  "@app/*": ["app/*"],
  "@env/*": ["environments/*"]
}

Additionally, the server build is still not built correctly (without the paths)

@CaerusKaru
Copy link
Member Author

ng serve --aot issues fixed by #8188, deleted above comment.

@CaerusKaru
Copy link
Member Author

#8188 also fixes the ng build --prod issues for the browser build, but the server build is still busted.

@vikerman
Copy link
Contributor

Can reproduce the server issue with Angular rc.6 and CLI 1.5 RC.3 and universal-starter repo.

LAZY_MODULE_MAP generated inside the server bundle has reference to the Module instead of the NgModuleFactory - causing factory.create to be undefined.

@hansl
Copy link
Contributor

hansl commented Oct 26, 2017

We have a separate fix for lazy modules in ng5. The problem is that making it work for ng5 seems to break ng4 so we'll do another RC with this fix whren it's ready (today hopefully)

@CaerusKaru
Copy link
Member Author

In case 7a36f6a was designed to be the fix, it does not fix the issue.

@Toxicable
Copy link

@CaerusKaru what error are you getting?
the universal-starter upgraded to the latest versions is working fine for me

@CaerusKaru
Copy link
Member Author

@Toxicable To be clear, this is when you import an Angular Material module into any NgModule (lazy-loaded or otherwise). You can use my sample repo as a starter. The error has not changed from the one initially posted.

@hansl hansl added this to the v1.5.0 milestone Oct 27, 2017
@vikerman
Copy link
Contributor

@CaerusKaru - hey - I think we started using this bug to track the factory.create error because we started seeing that in the universal starter.

We will look into the original 'Module not Found' issue.

@hansl
Copy link
Contributor

hansl commented Oct 30, 2017

Duplicate of angular/angular#20031

@hansl hansl marked this as a duplicate of angular/angular#20031 Oct 30, 2017
@hansl hansl closed this as completed Oct 30, 2017
@hansl
Copy link
Contributor

hansl commented Oct 30, 2017

Please follow the discussion over the other issue, as this is an issue from Angular's own ngc, which has a fix already in flight. Thanks!

@CaerusKaru
Copy link
Member Author

Thanks to everyone on this issue for tracking this down and getting a fix out so quickly. You all rock!

@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken
Projects
None yet
Development

No branches or pull requests

7 participants