ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
OS?
Windows 7 64 bit
Versions.
@angular/cli: 1.0.0-beta.30 node: 7.4.0 os: win32 x64 @angular/common: 2.4.6 @angular/compiler: 2.4.6 @angular/core: 2.4.6 @angular/forms: 2.4.6 @angular/http: 2.4.6 @angular/platform-browser: 2.4.6 @angular/platform-browser-dynamic: 2.4.6 @angular/router: 3.4.6 @angular/cli: 1.0.0-beta.30 @angular/compiler-cli: 2.4.6
Repro steps.
App started using angular cli
The log given by the failure.
This is from my command line:
ERROR in Unexpected value 'null' declared by the module 'AppModule in C:/Users/T haniri/Desktop/freecodecamp/myroute/src/app/app.module.ts'
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\Users\Thaniri\Desktop\freecodecamp\myroute\src' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts
Mention any other details that might be useful.
ng serve works fine, its just ng build -prod
Here are the contents of my main.ts file: `import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; import { AppModule } from './app/app.module';
if (environment.production) { enableProdMode(); }
platformBrowserDynamic().bootstrapModule(AppModule); `
If there is more information needed, please let me know. I am trying to learn how to deploy my Angular website.
Having the same failure on both linux and windows platforms.
ERROR in Cannot read property 'map' of undefined
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/helix-app.module.ngfactory' in 'C:\Users\agarbutt\WebstormProjects\helix-ui\src'
@ ./src/main.ts 3:0-85
@ multi ./src/main.ts
main.ts
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {enableProdMode} from "@angular/core";
import {environment} from "./environments/environment";
import {HelixAppModule} from "./app/";
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic()
.bootstrapModule(HelixAppModule)
.catch(err => console.error(err));
+1
+1 (on Windows 10 64bits)
+1 linux mint
ERROR in this._input.charCodeAt is not a function
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/vs/Work/GoFactTables/GoFactFrontend/src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts
This may or may not be helpful but I have noticed that the first error seems to be the primary cause and the Module not found error is generic and will happen any time something breaks the aot build.
In my case I was getting the following any time I had an empty scss file:
ERROR in Child compilation failed:
Module build failed: No input specified: provide a file name or a source string to process:
[object Object]
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/mhamel/Development/blispay/blispay-ui2/src'
@ ./src/main.ts 4:0-76
@ multi ./src/main.ts
As soon as I fixed the first error, the Module not found error resolved itself. From that, I would expect @IlyaSurmay and @agarbutt each have different project specific bugs. (Possibly aot compiler related)
Can you see if the --verbose flag gives you any more information about the error?
http://pastebin.com/Hmrs0Kh7
CTRL+F the document for 'was generated' to find out what command I used: ng build -prod --verbose > aFile.txt ng build -prod --verbose
If you want to try it yourself please clone this repo: https://github.com/thaniri/angularPortfolio
I have no empty .scss files, and even if I attempt to add something to styles.css in the src folder, I get the same error.
The same thing happens for me. No error other than:
ERROR in ./src/client.aot.ts
Module not found: Error: Can't resolve './$$_gendir/browser.module.ngfactory' in '/home/pradej/Projekty/site-backoffice/src'
@ ./src/client.aot.ts 2:0-75
I had to make a separate, plain client entry point for AOT, but it still doesn't work.
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { MainModule } from './browser.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(MainModule);
OS: Fedora 25 x64
Also, if that's helpful, my project is using Universal, but AOT is used for client only.
I think it might be ngc. I cannot make it generate anything even when running it directly.
16.02.2017 4:43 PM "Ilya Surmay" [email protected] napisał(a):
+1 linux mint
ERROR in this._input.charCodeAt is not a function
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/vs/Work/GoFactTables/GoFactFrontend/src' @ ./src/main.ts 5:0-74 @ multi ./src/main.ts
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/4551#issuecomment-280366544, or mute the thread https://github.com/notifications/unsubscribe-auth/ATNfaOp3L5J0yev2EYWiQmUg8iZvNSx_ks5rdG6GgaJpZM4L7u-Y .
Same error when I upgraded to 4.0.0-beta.8. Previous version 4.0.0-beta.7 doesn't have this failure.
This is how I fixed my issues with the last version of angular-cli : https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.n4b11wso1
With the last version of angular-cli, ng build --prod seems to compile with --aot by default : I didn't know there was good practices to make project working with...
Similar problem with 1.0.0-rc1 on Windows. Running ng build --prod gives
ERROR in Error encountered resolving symbol values statically. Could not resolve events relative to C:/Projects/craft-ng/editor/node_modules/blocking-proxy/built/lib/webdriver_commands.d.ts., resolving symbol WebDriverCommand in C:/Projects/craft-ng/editor/node_modules/blocking-proxy/built/lib/webdriver_commands.d.ts
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\Projects\craft-ng\editor\src' @ ./src/main.ts 4:0-74 @ multi ./src/main.ts
ng build --prod --aot=false executes without problems.
This issue was closed, any advice for people still sufferring from this error?
Just to tell everyone: I eventually dropped @ngtools/webpack completely from my project and replaced it with @ultimate/aot-loader. AOT now finally works.
Instead of use
ng build --prod
use
ng build --env=prod
UPDATE
As many of us (thx) have mention, this doesn't build with aot so, it's the same that the plain ng build at the end (as says @adessilly ng build --env=prod : replace environment.ts by environment.prod.ts, but it's a simple ng build. ng build --prod : improved build with aot + environment.prod.ts replacement (before, it was ng build --prod --aot) )
The most easy workaround (at least for me), was to create a new whole project with the last Angular CLI version, and moves the src folder. It's no straight forward, so please read the migration guide and don't forget to make a backup before.
@WiL-dev : I can confirm it works fine on 1.0.0-rc1. Thanks!
@WiL-dev - I'm not sure ng build --env-prod builds with aot like ng build --prod does. If I run ng build --env=prod the tool generates the same size for my output as ng build --env=dev does. In addition running ng build --env=prod --aot=true gnerates the same error that I was origially getting. Unexpected value 'null' exported by the module 'MyModule' && down the stack Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
This leads me to suspect that the cli tool is fine and it's my app that needs some updates before it can be --aot compiled.
Something I'll look into when I have a bit of time.
unresolved, --env produces not the same output as --prod
@russkayairina it's a normal behavior :
ng build --env=prod : replace environment.ts by environment.prod.ts, but it's a simple ng build.
ng build --prod : improved build with aot + environment.prod.ts replacement (before, it was ng build --prod --aot).
To make your project working with aot, follow these steps : https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.n4b11wso1
This is still a problem. It happens even with the newly created project from ng new!
Full output:
d:\Temp\cli>ng -v
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
@angular/cli: 1.0.0
node: 6.9.1
os: win32 x64
d:\Temp\cli>ng new cli-test
installing ng
create .editorconfig
create README.md
create src\app\app.component.css
create src\app\app.component.html
create src\app\app.component.spec.ts
create src\app\app.component.ts
create src\app\app.module.ts
create src\assets\.gitkeep
create src\environments\environment.prod.ts
create src\environments\environment.ts
create src\favicon.ico
create src\index.html
create src\main.ts
create src\polyfills.ts
create src\styles.css
create src\test.ts
create src\tsconfig.app.json
create src\tsconfig.spec.json
create src\typings.d.ts
create .angular-cli.json
create e2e\app.e2e-spec.ts
create e2e\app.po.ts
create e2e\tsconfig.e2e.json
create .gitignore
create karma.conf.js
create package.json
create protractor.conf.js
create tsconfig.json
create tslint.json
Successfully initialized git.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Project 'cli-test' successfully created.
d:\Temp\cli>cd cli-test
d:\Temp\cli\cli-test>ng build --prod --env=prod
Hash: 0bfde11b73d9b21b101b
Time: 6189ms
chunk {0} polyfills.7fd9b43f06a670d8299a.bundle.js (polyfills) 158 kB {3} [initial] [rendered]
chunk {1} (styles) 1.72 kB {3} [initial] [rendered]
chunk {2} main.e1bb4892ef6fedc166cd.bundle.js (main) 806 kB [initial] [rendered]
chunk {3} inline.65cd0835207a2ba3e811.bundle.js (inline) 0 bytes [entry] [rendered]
ERROR in E:/Temp/cli/cli-test/src/main.ts
Module not found: Error: Can't resolve './d:/Temp/cli/cli-test/src/$$_gendir/app/app.module.ngfactory' in 'E:\Temp\cli\cli-test\src'
@ E:/Temp/cli/cli-test/src/main.ts 4:0-99
@ multi ./src/main.ts
d:\Temp\cli\cli-test>