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

[1.5.0-beta.3] AOT build failed - Module not found (Can't resolve './app.ngfactory') #7925

Closed
MrBlaise opened this issue Oct 4, 2017 · 14 comments · Fixed by #8197
Closed
Assignees
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken type: bug/fix

Comments

@MrBlaise
Copy link

MrBlaise commented Oct 4, 2017

Bug Report or Feature Request (mark with an x)

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

Versions.

angular-cli: 1.5.0-beta.3

Repro steps.

Upgraded angular-cli from 1.4.4 to 1.5.0-beta.3 and tried to build it with
ng build --prod --aot --build-optimizer

Using version 1.4.4 everything works.

The log given by the failure.

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app.ngfactory' in 'D:\Development\frontend\src'
resolve './app.ngfactory' in 'D:\Development\frontend\src'
  using description file: D:\Development\frontend\package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: D:\Development\frontend\package.json (relative path: ./src)
    using description file: D:\Development\frontend\package.json (relative path: ./src/app.ngfactory)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        D:\Development\frontend\src\app.ngfactory doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        D:\Development\frontend\src\app.ngfactory.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        D:\Development\frontend\src\app.ngfactory.js doesn't exist
      as directory
        D:\Development\frontend\src\app.ngfactory doesn't exist
[D:\Development\frontend\src\app.ngfactory]
[D:\Development\frontend\src\app.ngfactory.ts]
[D:\Development\frontend\src\app.ngfactory.js]
[D:\Development\frontend\src\app.ngfactory]
 @ ./src/main.ts 3:0-54
 @ multi ./src/main.ts

Desired functionality.

AOT build should work.

Mention any other details that might be useful.

Angular 5.0.0-rc.0
yarn 1.1.0
Windows 10
node v8.1.4

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

Heya, are you using Angular 4 or 5? Are there other errors shown before that? That error usually comes up when the application fails to compile at all. I can take a look if you provide a repro.

@filipesilva filipesilva added the needs: repro steps We cannot reproduce the issue with the information given label Oct 10, 2017
@jinder
Copy link

jinder commented Oct 10, 2017

@filipesilva For me, this error occurred simply upgrading from Angular 4 to 5, without changing any other dependencies.

@filipesilva
Copy link
Contributor

@jinder it's a generic error really. It's lengthy but just really means that AOT compilation failed. v1.5.0-beta.4 should show a much shorter error instead.

Either way, I can't reproduce it in a new project... there's more to the problem. If someone can provide a reproduction it would help.

@jinder
Copy link

jinder commented Oct 10, 2017

@filipesilva I'll investigate more on my side. Was hoping it'd be easy to nail down, but it's on a massive project and the error message isn't terribly informative!

@filipesilva
Copy link
Contributor

You sure there isn't any other error message before or after this one? Also, what version of the CLI are you using?

@MrBlaise
Copy link
Author

@filipesilva I'm on Angular 5.0.0-rc.0 as I mentioned in the issue and I too just upgraded the cli from version 1.4.x to 1.5.0-beta.3 and this error occurred. This happened on a quite large project but the only error message I got was the one I provided. I can't test it with the latest cli right now but once I have the opportunity I'll look into it again.

@jinder
Copy link

jinder commented Oct 11, 2017

@filipesilva no other error. It was CLI 1.5.0-beta 3. I've got some big deliverables to ship by end of next week, but if nobody's solved it by then I'll start stripping things out to see if I can pinpoint the error. Is there any way to get some more info from the error description?

@jinder
Copy link

jinder commented Oct 12, 2017

@filipesilva Think I've figured it out through a process of elimination. It's caused by the the fact that the 'index.ts' bootstrap file was importing the app module via a barrel. So, changing this:

import { AppModule } from "./app";

to:

import { AppModule } from "./app/app.module";

Fixed it. Weirdly this is only a problem with Angular 5 (did not happen in Angular 4).

@MrBlaise Does this fix it for you?

@jmcgoldrick
Copy link

jmcgoldrick commented Oct 14, 2017

Thanks @jinder importing the module directly resolved the issue for me. @filipesilva you can repro by simply adding an index.ts alongside app.module.ts that looks like this:

export { AppModule } from "./app.module";

and in main.ts doing this import { AppModule } from "./app";

It results in the error above, key point is that it is trying to find the module at a path like this (not the lack of module/folder path added):

path/to/project/src/app.ngfactory doesn't exist

To note: I only updated the AppModule import as per @jinder suggestions and everything compiled. I left all other module imports as coming from their "barrel" and had no issues

@MrBlaise
Copy link
Author

MrBlaise commented Oct 16, 2017

@jinder Sorry for the late response, I was away for a week. Your workaround did indeed solve my problem as well, thanks! (Works with the latest rc.0 version as well with Angular 5.0.0-rc.0)

I am having weird errors with the latest Angular version, but that is probably another issue

EDIT:

It was a problem on my end, so everything works with latest cli and angular

@filipesilva
Copy link
Contributor

@jinder @jmcgoldrick thanks for the repro, that tells me exactly what's going on. It has to do with how we automatically refactor code to load AOT factories in main.ts. Specifically, how we read the path to the main module.

@filipesilva filipesilva added type: bug/fix and removed needs: repro steps We cannot reproduce the issue with the information given labels Oct 20, 2017
@filipesilva
Copy link
Contributor

I'm not sure if we can manage to actually fix it though, because we need the real path to app.module.ts somewhere, since the ngfactory will be created side by side... with a barrel reexporting it, the path is generally lost.

@filipesilva filipesilva added P5 The team acknowledges the request but does not plan to address it, it remains open for discussion and removed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful labels Oct 20, 2017
@jinder
Copy link

jinder commented Oct 20, 2017

@filipesilva Was a pretty easy fix once found. Could suffice to have a more informative error message.

@filipesilva filipesilva added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful and removed P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels Oct 25, 2017
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 26, 2017
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 26, 2017
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 26, 2017
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 26, 2017
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 26, 2017
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 26, 2017
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 26, 2017
asnowwolf pushed a commit to asnowwolf/angular-cli that referenced this issue Nov 2, 2017
asnowwolf pushed a commit to asnowwolf/angular-cli that referenced this issue Nov 2, 2017
dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
@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 type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants