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

[AOT] @ngtools/webpack throws "Cannot find module './ngfactory/app/app.module.ngfactory'" #2586

Closed
DzmitryShylovich opened this issue Oct 8, 2016 · 19 comments
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful type: bug/fix

Comments

@DzmitryShylovich
Copy link

DzmitryShylovich commented Oct 8, 2016

OS?

Windows_NT 10.0.10586

Description.

I'm trying to integrate @ngtools/webpack into my custom webpack build and is getting Cannot find module './ngfactory/app/app.module.ngfactory' error. The source of the error is here. I've managed to suppress the error by disabling this check.

Repro steps.

Github repo: https://github.com/DzmitryShylovich/ngtools-error

npm i
npm start

The log given by the failure.

ERROR in ./app/main.aot.ts
Module build failed: Error: D:/Workspace/ngtools-error/app/main.aot.ts (3,34): Cannot find module './ngfactory/app/app.module.ngfactory'.)
    at _transpile (D:\Workspace\ngtools-error\node_modules\@ngtools\webpack\src\loader.js:101:19)
    at D:\Workspace\ngtools-error\node_modules\@ngtools\webpack\src\loader.js:125:26
@DzmitryShylovich DzmitryShylovich changed the title [AOT] @ngtools/webpack throws [AOT] @ngtools/webpack throws "Cannot find module './ngfactory/app/app.module.ngfactory'" Oct 8, 2016
@david1880
Copy link

david1880 commented Oct 10, 2016

I tryed to run the starting material2 project and I had a similar problem with ngfactory. In main.ts I finded this comment:
`

AoT compile.
First run ./node_modules/.bin/ngc -p ./src/

`
After running that it worked, maybe you can try this.

@filipesilva
Copy link
Contributor

@DzmitryShylovich what version of @ngtools/webpack are you using?

@DzmitryShylovich
Copy link
Author

DzmitryShylovich commented Oct 10, 2016

the latest 1.1.0

@DzmitryShylovich
Copy link
Author

Basically I've just copy pasted test app so it might be Windows specific issue.

@filipesilva filipesilva added type: bug/fix command: build P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful and removed needs: more info Reporter must clarify the issue type: RFC / discussion / question labels Oct 10, 2016
@Gamblt
Copy link

Gamblt commented Oct 11, 2016

I have the same error. But if a try to go back to the beta16 I've got error:
webpack_1.NgcWebpackPlugin is not a constructor TypeError: webpack_1.NgcWebpackPlugin is not a constructor

@jtsom
Copy link
Contributor

jtsom commented Oct 11, 2016

I saw this same error also, when running ng serve -aot However, when I changed a file (added a new <p> ... </p> in app.component.html for instance) the error would not show after the project rebuilt. Making any other change would show the error.. and so on, alternately showing and not showing the error.

@michaelbromley
Copy link

I have the same on Windows 10, but also is occurring in my Travis build on mac OS. You can see the full output of that here: https://travis-ci.org/michaelbromley/skqw/jobs/166849701#L466

I just updated to v1.1.0.

@Delagen
Copy link

Delagen commented Oct 12, 2016

#2452

@sdeuvarow
Copy link

sdeuvarow commented Oct 31, 2016

It's happening again to me. When I run
> ./node_modules/.bin/ngc -p ./src/
I don't get any error, and all ng-factories are created. But when I run
> ng build

I get the following error:
...\AppData\Roaming\npm\node_modules\ng-cli\node_modules\resolve\lib\sync.js:33 throw new Error("Cannot find module '" + x + "' from '" + y + "'");

Error: Cannot find module 'ng-factory' from '...\workspaceFrontend
at Function.module.exports [as sync] (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\resolve\lib\sync.js:33:11)
at module.exports (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\resolve-require\lib\index.js:10:24)
at Command.<anonymous> (..\AppData\Roaming\npm\node_modules\ng-cli\lib\index.js:35:5)
at Command.listener (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\commander\index.js:301:8)
at emitTwo (events.js:106:13)
at Command.emit (events.js:191:7)
at Command.parseArgs (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\commander\index.js:615:12)
at Command.parse (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\commander\index.js:458:21)
at Object.<anonymous> (C:\Users\Simon\AppData\Roaming\npm\node_modules\ng-cli\lib\index.js:55:9)
at Module._compile (module.js:570:32)

Two days ago I didn't have any problems to create the distribution of the app.
Any idea how to fix this?

NODE v6.9.1
NPM v3.10.6
TSC v2.0.0
angular-cli@1.0.0-beta.19-3
ng-cli@0.7.0

I tried in windows and also in linux. In both OS get the same error.

Maybe this is a different issue?

>npm start works fine
>npm build doesn't do anything , I think because ng build crashes

@fcrocce
Copy link

fcrocce commented Oct 31, 2016

Same as @sdeuvarow for me... in my case from ubuntu 16.04

@sdeuvarow
Copy link

I had a conflict with "ng-cli" package. Removing it and reinstall angular-cli fix the issue.

@Meligy
Copy link
Contributor

Meligy commented Jan 16, 2017

Anyone still getting this?

@zoehneto
Copy link

zoehneto commented Jan 17, 2017

I'm still seeing this issue with @ngtools/webpack 1.2.3. Interestingly enough it works if I have the site open before running ´npm start´ but then it imediatly recompiles and throws the error.

@hansl
Copy link
Contributor

hansl commented Feb 3, 2017

Closing this as obsolete. Please provide a git repo that we can try to reproduce.

@hansl hansl closed this as completed Feb 3, 2017
@karthikeyanVK
Copy link

When you run the ng build in angular 2, latest angular-cli automatically runs with --aot parameter (ahead of time compilation), so it is trying to optimize your code. You are having a package that is not yet compatible for optimizing. So you need update to your packages. Most probably the packages that has forRoot() in your app.module.ts

I recommend to update all packages.

Easy way to update your package is to the use package below, which i got it from http://stackoverflow.com/questions/36597780/how-do-i-correctly-upgrade-angular-2-npm-to-the-latest-version

Install

npm install -g npm-check-updates

Usage

ncu for display

ncu -u for re-writing your package.json

and run npm install to update your packages

@18steps
Copy link

18steps commented May 25, 2017

Check if your tsconfig.json has the following at the root level:

  "angularCompilerOptions": {
    "genDir": "src/ngfactory",
    "entryModule": "./src/app#AppModule"
  }

I had accidentally left that out and for me it fixed the problem.

@snewell92
Copy link

@18steps that didn't work for me 😿

I was trying to follow the docs for aot compilation, and the only difference I have is I want JIT to be the default main.ts and AOT be opt in with main-aot.ts (so I can bundle scripts just for production, automatically, with a postinstall script or whatever).

My aot folder output is also one directory level above my src directory -

  "angularCompilerOptions": {
    "genDir": "../aot",
    "basePath": "./src/", // this doesn't change anything :c
    "entryModule": "./src/app#AppModule" // this didn't help either :c
  }

And inside that aot folder it doesn't include the compiled main-aot.ts file, it just has app folder with broken .ngfactory.ts and .ngsummary.ts files, all of which have ts errors because they're import urls are wrong.

Can I not have my aot output be somewhere else? genDir is constrained?

@snewell92
Copy link

Maybe #1465 would help me actually.

@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 type: bug/fix
Projects
None yet
Development

No branches or pull requests