AOT build fails
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
@angular/cli: 1.2.3
node: 6.11.1
os: darwin x64
@angular/animations: 4.3.1
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.3
@angular/compiler-cli: 4.3.1
@angular/language-service: 4.3.1
Repro steps.
$ ng new hello
$ cd hello
$ ng build --prod
The log given by the failure.
$ ng build --prod
Hash: edf6fb3ccb1b82fa940c
Time: 10775ms
chunk {0} polyfills.71b130084c52939ca448.bundle.js (polyfills) 177 kB {4} [initial] [rendered]
chunk {1} main.e81f19d3f6b27a436c79.bundle.js (main) 1.09 kB {3} [initial] [rendered]
chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered]
chunk {3} vendor.f7457d5ac1e9743fd76f.bundle.js (vendor) 849 kB [initial] [rendered]
chunk {4} inline.18e445e37a0efd4dcfa2.bundle.js (inline) 0 bytes [entry] [rendered]
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'hello/src'
@ ./src/main.ts 3:0-74
@ multi ./src/main.ts
Desired functionality.
aot build runs
Mention any other details that might be useful.
Maybe, enhanced-resolve 3.4.0 is cause. https://github.com/webpack/enhanced-resolve/issues/98
ng build --prod runs successfully after npm i [email protected] .
Using @ngtools/[email protected] did not solve the issue for me. I had to manually install [email protected] after running npm install and then had to copy/paste node_modules/enhanced-resolve to node_modules/webpack/node_modules/enhanced-resolve for this to work.
@filipesilva But of course! Thank you 😄
I'm running [email protected] and [email protected] on Windows 10 (under a cmdr shell).
My global Angular CLI is 1.2.6, matching that installed in my project:
λ npm ls -g @angular/cli
`-- @angular/[email protected]
Here is my project's package.json:
{
"name": "prod-test-fail",
"version": "1.0.0",
"private": true,
"dependencies": {
"@angular/animations": "^4.3.1",
"@angular/common": "^4.3.1",
"@angular/compiler": "^4.3.1",
"@angular/core": "^4.3.1",
"@angular/forms": "^4.3.1",
"@angular/http": "^4.3.1",
"@angular/platform-browser": "^4.3.1",
"@angular/platform-browser-dynamic": "^4.3.1",
"@angular/router": "^4.3.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"jquery": "^3.2.1",
"moment": "^2.18.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.2.6",
"@angular/compiler-cli": "^4.3.1",
"@angular/language-service": "^4.3.1",
"@types/core-js": "^0.9.42",
"@types/jquery": "^3.2.9",
"@types/node": "8.0.17",
"codelyzer": "^3.1.2",
"ts-node": "~3.3.0",
"tslint": "^5.5.0",
"typescript": "^2.4.2"
}
}
This morning, I deleted node_modules/ folder, the package-lock.json and npm installed the above package with the following results:
Output of ng build:
λ ng build
Hash: 02193d0724fa51e87a0d
Time: 24523ms
chunk {0} main.bundle.js, main.bundle.js.map (main) 2.24 MB {2} [initial] [rendered]
chunk {1} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 174 kB {3} [initial] [rendered]
chunk {2} vendor.bundle.js, vendor.bundle.js.map (vendor) 3.89 MB [initial] [rendered]
chunk {3} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
Output of ng build --prod and ng build --aot:
λ ng build --prod
Hash: adc8c0af1f195a4cd49a
Time: 6075ms
chunk {0} polyfills.dd983c51be469b02aa15.bundle.js (polyfills) 174 kB {3} [initial] [rendered]
chunk {1} main.10609bd5e9ef4fd0b393.bundle.js (main) 713 bytes {2} [initial] [rendered]
chunk {2} vendor.a590f07d547ec4b39908.bundle.js (vendor) 849 kB [initial] [rendered]
chunk {3} inline.bf6c517a9f6f64c103ca.bundle.js (inline) 0 bytes [entry] [rendered]
ERROR in Cannot determine the module for class ModalInstanceComponent in C:/Users/<me>/app/src/ui/src/app/components/modal/modalInstance.ts! Add ModalInstanceComponent to the NgModule to fix it.
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './../$$_gendir/src/app.module.ngfactory' in 'C:\Users\<me>\app\src\ui\src'
@ ./src/main.ts 3:0-77
@ multi ./src/main.ts
It may be worth noting (should this somehow be the true source of my problem) that this is an angular 2 project born in beta-6 which we have progressively kept up to date every 3 weeks as angular has been updated.
I have made rather extensive changes to the the project to allow it to compile with ng. I followed the more-or-less accepted guide of creating a template project with ng new and copying files and library changes in manually.
This explains the outstanding ModalInstanceComponent error: it has no template and is instantiated in another component. If I include it in my main @NgModule, it throws a cascade of new errors, so I have left it as-is for now. I imagine this is (now?) an anti-pattern and will revisit it.
This types issue cropped up at about same time, but may be unrelated. I don't seem to encounter this error now with 0.8.17, but it may encounter the can't resolve $$_gendir error first. I've tried with both .17 and .16.
(And for those who may have cringed, yes, I'm removing jQuery 😉.)
@michaelsanford ah, I see now: the first error you get is actually causing the second:
ERROR in Cannot determine the module for class ModalInstanceComponent in C:/Users/
/app/src/ui/src/app/components/modal/modalInstance.ts! Add ModalInstanceComponent to the NgModule to fix it.
Since that fails, AOT doesn't compile anything really so you get the second error:
Module not found: Error: Can't resolve './../$$_gendir/src/app.module.ngfactory'
Which is true (but hard to interpret).
You have to fix the first error to get right of the second.
@filipesilva I had a strong suspicion that might be the case; thank you very much for looking into it and confirming, we've not tried AOT prior to using ng.
I suspect we still have a lot of AOT-incompatible code. I have a refactoring task to move this template-less @Component to a @Directive (I'm not even sure why it was written this way).
Update for others with a problem like this who still want a prod bundle and who just started using ng, the following emits a functional application package:
ng build --prod --aot=false
Good find @filipesilva ! So does this only affect projects that use modals? Ours only just added our first modal, so is that why we are 'suddenly' experiencing this issue? Having said that, our other app does not use modals, and gets this error too...
@russelltrafford not modals per se, but overall components that are not in any NgModule.
[email protected] not work for me
Include this line in package.json "enhanced-resolve": "3.3.0" run npm install and ng build --prod Thanks
Hi everybody, i remove a unused component and it works. I hope the angular team attached importance to this error, too difficult to locate.
When I run ng build --prod, does it complain about private form variables, any solution to this or do I really have to put everything as public?
You should make all the members which are accessed from the template, public, instead of private. I think it will solve your issue @ThalesMatoso
Cool ... this is going to work, but if you talk about a bigger system, can not you come and get in the way? Really is the only alternative?
@ThalesMatoso When you reference fields of a component's class in its template, you are really writing instructions for Angular's rendering engine to take those values and display them on the DOM. Since the renderer is separate from and external to the component's class, attempts to access private variables will result in a TypeScript compilation error. Thus any fields in your component's class which might be touched by external services, such as those referenced in your template or annotated with decorators like @ViewChild, must be public.
Also, just to be clear, this is an Angular feature/requirement. Not specific to CLI.
Am I correct in thinking that the npm i [email protected] is not a reliable fix? @angular/[email protected] depends on [email protected] which in turn depends on [email protected]. npm seems fairly determined to make sure that webpack gets what it asks for.
I've tried installing [email protected] and it worked once, but then I ran npm install again and it stopped working. Am I missing something or is it rather difficult to get around this in a stable way?
@studds you shouldn't need to add enhanced-resolve manually with the newer versions.
Installing "enhanced-resolve": "^3.3.0" solved it for me
I have enhanced resolve 3.3.0 and ngtools webpack 1.6.2, Still seeing errors
Field 'browser' doesn't contain a valid alias configuration after using description file: /Users/ui/package.json (relative path: ./src/app/Components/selector)
"@angular/animations": "^4.3.6", "@angular/cdk": "2.0.0-beta.8", "@angular/common": "^4.3.6", "@angular/compiler": "^4.3.6", "@angular/compiler-cli": "^4.3.6", "@angular/core": "^4.3.6", "@angular/forms": "^4.3.6", "@angular/http": "^4.3.6", "@angular/material": "^2.0.0-beta.8", "@angular/platform-browser": "^4.3.6", "@ngrx/core": "^1.0.2", "@ngrx/effects": "^2.0.0", "@ngrx/store": "^2.1.2", "@ngtools/webpack": "^1.6.2", "enhanced-resolve": "^3.3.0",
Finaly makes it work with devDependencies "@angular/cli": "1.2.6" and dependencies "enhanced-resolve": "3.3.0" and @angular/*:"^4.3.6"
I am getting this error while creating new angular project.
Installing packages for tooling via npm. npm ERR! Windows_NT 10.0.10240 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "--quiet" "install" npm ERR! node v6.10.0 npm ERR! npm v3.10.10
npm ERR! shasum check failed for C:\Users\Sukeshu\AppData\Local\Temp\npm-3120-1165392c\registry.npmjs.org\jasmine-spec-reporter-\jasmine-spec-reporter-4.1.1.tgz npm ERR! Expected: 5a6d58ab5d61bea7309fbc279239511756b1b588 npm ERR! Actual: 1cca12519560608e42bb4efd78f30d818740a4f9 npm ERR! From: https://registry.npmjs.org/jasmine-spec-reporter/-/jasmine-spec-reporter-4.1.1.tgz npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! https://github.com/npm/npm/issues
npm ERR! Please include the following file with any support request: npm ERR! C:\Users\Sukeshu\Desktop\ng2\dapp\npm-debug.log
Package install failed, see above. Package install failed, see above.