New version of cli `ng build --prod` gives error.
Bug Report
- [X] bug report
- [ ] feature request
Versions.
Output from: ng --version.
@angular/cli: 1.0.0-rc.2
node: 7.6.0
os: linux x64
@angular/cli: 1.0.0-rc.2
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
Repro steps.
Nothing changed. Problem is happening after upgrading CLI version to rc.2.
I read the issue https://github.com/angular/angular-cli/issues/5623 , but it is closed without any solution. It is nearly impossible to change all properties to public, because project is too big.
I tried to change, but I gave up now.
Strange thing is build on Github through Codeship is succeed. How is it possible? And why not on local?
The log given by the failure.
ERROR in /home/rango/Desktop/test/accepter/ng-reason/src/$$_gendir/app/components/home/home.component.ngfactory.ts (1038,49): Property 'test_detail_mode' is private and only accessible within class 'HomeComponent'.
/home/rango/Desktop/test/accepter/ng-reason/src/$$_gendir/app/components/home/home.component.ngfactory.ts (1041,44): Property 'test_detail_mode' is private and only accessible within class 'HomeComponent'.
ERROR in /home/rango/Desktop/test/accepter/ng-reason/src/$$_gendir/app/components/reason/reason.component.ngfactory.ts (1230,44): Property 'hours' is private and only accessible within class 'ReasonComponent'.
/home/rango/Desktop/test/accepter/ng-reason/src/$$_gendir/app/components/reason/reason.component.ngfactory.ts (1234,50): Property 'statistic' is private and only accessible within class 'ReasonComponent'.
... ... ...
Desired functionality.
Is there anyway to upgrade codebase without changing all issues by manually?
Migrating all issues line by line is too pain for us, also creating getter, setter is same for us.
Mention any other details that might be useful.
I think if this error is too critical then CLI should gives error on ng serve or ng build.
Thank you very much.
Me, personally that seems like "possibly" a good way to hide certain behaviour, without reading I don't know what that setting does, I would prefer to have everything up to date and building correctly which just took us a bit of time.
I have total faith in the team because they fixing things very well as they come up on subsequent minor releases and we are very happy with what is coming out.
This link wasvery helpful https://github.com/qdouble/angular-webpack2-starter#aot--donts Still have a problem using pipes
We have fixed all private methods and variables that were called from html and now it builds perfect.
On May 16, 2017 1:42 PM, "Ian Sam Mungai" [email protected] wrote:
This link wasvery helpful https://github.com/qdouble/angular-webpack2-starter#aot--donts Still have a problem using pipes
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5733#issuecomment-301756212, or mute the thread https://github.com/notifications/unsubscribe-auth/AQ65fet0aKaf6D6MkAMCRhqqaUv_hNcVks5r6YuQgaJpZM4MtGxa .
@iansamz By pipes do you mean pipes used to transform data or do you mean pipes used to indicate that parameters may be of several types (aka | as an OR operator)? If it's the later, see this comment https://github.com/angular/angular-cli/issues/5623#issuecomment-289577009
@ben-coble-sp fixed it just an error on my side
I'm still error with this issue.
$ ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | ' \ / _ | | | | |/ _ | '| | | | | | |
/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@angular/cli: 1.1.3
node: 8.1.2
os: win32 x64
@angular/animations: 4.2.4
@angular/common: 4.2.4
@angular/compiler: 4.2.4
@angular/core: 4.2.4
@angular/forms: 4.2.4
@angular/http: 4.2.4
@angular/material: 2.0.0-beta.7
@angular/platform-browser: 4.2.4
@angular/platform-browser-dynamic: 4.2.4
@angular/platform-server: 4.2.4
@angular/router: 4.2.4
@angular/cli: 1.1.3
@angular/compiler-cli: 4.2.4
I'm not sure, Is is another solution instead of change private to public?
I had an error in my templates which only showed up when building with --aot. I Isolated it by removing template to make sure that's where it was and then just searching through the events until I found calls that didn't match the signatures of their methods. Once, I fixed that, it compiled with --aot. Would have been better to have a more helpful error message.
I had the following case: with "ng build" worked fine.
with "ng build -prod" failed with:
ERROR in ..../src/$$_gendir/app/app.module.ngfactory.ts (499,57): Supplied parameters do not match any signature of call target.
In app modules had:
providers: [
{
provide: Http,
useFactory: translateHttpServiceLoader,
deps: [XHRBackend, RequestOptions]
}
]
and
export function translateHttpServiceLoader(backend: XHRBackend, options: RequestOptions, router: Router) {
return new HttpService(backend, options, router);
}
I've found that useFactory should have only 2 params.
I've removed the last param and now is building fine also with "ng build -prod"
working version:
export function translateHttpServiceLoader(backend: XHRBackend, options: RequestOptions) {
return new HttpService(backend, options);
}
xxx How do we make ng serve show us the errors that ng build -prod does? xxx
Just upgraded to latest angular-cli 1.2.7 (but was having the same issues right before with 1.0.0-beta30 as well)
@angular/cli: 1.2.7
node: 7.5.0
os: darwin x64
@angular/animations: 4.0.0
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.2.7
@angular/compiler-cli: 4.0.0
ng build -prod is giving me ~400's of errors like this, which I do NOT get in ng serve:
Property 'editing' is private and only accessible within class 'XxxxxxXxxxxComponent'.
Property 'name' does not exist on type 'Object'.
This last error is coming from html template where we do myObject.name... apparently it wants myObject['name'], which is annoying :) But ok, I can change to any to fix this...
I'm fine fixing these, but HOW do I get ng serve to inform us during development rather than surprise us later when building ng build -prod for production??? That is going to be a bad thing for us, i'd like to avoid.
Backstory:
We used to use 1.0.0-beta30 for months, just fine, many clean npm installs, no errors when using ng build -prod. (1.0.0-beta30 of @angular/cli and 2.3.1 of @angular/core and friends).... until today.
For some reason this bug JUST showed up for us in the last two days after one of us did a rm -rf node_modules && npm install && ng build -prod - the others on the team could still build with -prod fine, but immediately break when they issue the same npm install command!! ... Which prompted us to upgrade to latest 1.2.7 cli which uses angular 4.0.0. And we use all fixed versions in our package.json, so some sub dep must have changed in npm to cause this because our versions are fixed (wtf indeed).
part of package.json
"dependencies": {
"@angular/animations": "4.0.0",
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/core": "4.0.0",
"@angular/forms": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-browser-dynamic": "4.0.0",
"@angular/router": "4.0.0",
"@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.14",
"@types/mixpanel": "0.0.28",
"angular2-autosize": "1.0.1",
"angular2-medium-editor": "1.0.6",
"angular2-notifications": "0.4.51",
"angular2-uuid": "1.1.1",
"bootstrap": "4.0.0-alpha.5",
"core-js": "2.4.1",
"intl": "1.2.5",
"jquery": "3.1.1",
"lodash": "4.17.4",
"marked": "0.3.6",
"medium-editor": "5.22.2",
"medium-editor-markdown": "2.6.0",
"moment": "2.18.1",
"ng-click-outside": "2.0.2",
"ng2-select2": "1.0.0-beta.10",
"remove-markdown": "0.1.0",
"rxjs": "5.4.1",
"select2": "4.0.3",
"semaphore": "1.0.5",
"sweetalert2": "6.4.2",
"three": "0.86.0",
"ts-helpers": "1.1.1",
"zone.js": "0.8.14"
},
"devDependencies": {
"@angular/cli": "1.2.7",
"@angular/compiler-cli": "4.0.0",
"@types/jasmine": "2.5.53",
"@types/jasminewd2": "2.0.2",
"@types/lodash": "4.14.71",
"@types/medium-editor": "5.0.1",
"@types/node": "6.0.60",
"@types/selenium-webdriver": "2.53.36",
"@types/three": "0.84.19",
"codelyzer": "3.0.1",
"http-server": "0.10.0",
"jasmine-core": "2.6.2",
"jasmine-spec-reporter": "4.1.0",
"karma": "1.7.0",
"karma-chrome-launcher": "2.1.1",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "1.2.1",
"karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "0.2.2",
"karma-phantomjs-launcher": "1.0.0",
"karma-remap-istanbul": "0.2.1",
"karma-spec-reporter": "0.0.26",
"karma-verbose-reporter": "0.0.3",
"node-sass": "3.13.0",
"phantomjs-polyfill": "0.0.2",
"phantomjs-prebuilt": "2.1.7",
"protractor": "5.1.2",
"raw-loader": "0.5.1",
"sass-loader": "4.0.2",
"ts-node": "3.0.4",
"tslint": "5.3.2",
"typescript": "2.3.3",
"typings": "2.1.1",
"webdriver-manager": "10.2.5"
}
You can replicate this problem, by creating a brand new simple empty project, with this sequence:
-
ng new project(gives us@angular/cli1.2.7and@angular/coreand friends4.0.0) -
cd project -
edit
src/app/app.component.ts(changetitle = 'app';toprivate title = 'app';) -
npm start(works! but should not... very misleading during development)
> [email protected] start /Users/username/src/project
> ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
Hash: 7449fd53eff15e84d8b5
Time: 5212ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 177 kB {4} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.js.map (main) 5.28 kB {3} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial] [rendered]
chunk {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.19 MB [initial] [rendered]
chunk {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.
ng build -prod(doesn't work!)
Hash: d066ff91b21cc6eafccb
Time: 7596ms
chunk {0} polyfills.550cf10c9aa54b8194c7.bundle.js (polyfills) 177 kB {4} [initial] [rendered]
chunk {1} main.2149231fc44e7510bd2f.bundle.js (main) 13.5 kB {3} [initial] [rendered]
chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered]
chunk {3} vendor.330bdb50b9e3457f8646.bundle.js (vendor) 849 kB [initial] [rendered]
chunk {4} inline.95b082410a205220057a.bundle.js (inline) 0 bytes [entry] [rendered]
ERROR in /Users/username/src/project/src/$$_gendir/app/app.component.ngfactory.ts (57,31): Property 'title' is private and only accessible within class 'AppComponent'.
The apparent solution then is to make the variable public... easy on this toy project, hard on a old/large project with ~400+ errors.
From other threads, you can work around the problem. Meaning, you CAN use -prod or --aot without changing any private to public, or fixing other errors...
Tested with my Angular 4.0.0 described above, which was installed by [email protected]
Couple different ways to disable those errors in AoT mode:
Hack, which is not optimal and does not carry over on reinstalls.
npm install --save-dev @ngtools/[email protected]
rm -rf node_modules/\@angular/cli/node_modules/\@ngtools/webpack/
npm install --save-dev [email protected]
and pin those versions....
...Tested with [email protected].
...enhanced-resolve fixes the error Can't resolve './$$_gendir/app/app.module.ngfactory'
OR
A better workaround is to use @angular/[email protected] instead, as it carries over reinstalls and there isn't a big difference between the two versions.
"devDependencies": {
"@angular/cli": "1.0.0-rc.4",
"@ngtools/webpack": "1.2.14",
...
}
without the [email protected] from the first one or it wont work...
I tested both with a large project, and I no longer get those ~400+ errors about private and others when building with ng build -prod and ng serve --aot
Thanks to @filipesilva and @adwd References:
- https://github.com/angular/angular-cli/issues/5623#issuecomment-289072266 (@filipesilva)
- https://github.com/angular/angular-cli/issues/7113 (@adwd)
So, Out of the box @angular/[email protected] has an inconsistency between ng serve (allowing errors) and ng build -prod (where errors stop the show). See reproduction steps I posted above.
What is the long term solution going to be? Anyone know? Do we at least agree this should have a resolution?
I see 3 possibilities to fix this:
- Modify
ng serveto emit (and potentially stop on) the same errors asng build -prodso you're not surprised when making a prod build. - Modify
ng build -prodso that theseprivateerrors are ignored and dont 'stop the show' (or simply aren't errors). Like it works in the workaround I posted above. - Modify angular so that templates are compiled within the class scope, so html can reference
privatevars and make javascript styleobject.keyreferences instead ofobject['key']- so it is then correct to reference private vars from within a template. (maybe more of a philosophical point to decide)
Question: today, is there a flag I can use on ng serve which makes it emit those same errors as ng build -prod? Without --aot which seems too slow for our team (we dont want to give up the fast iteration).
Okay so how again are we suppose to figure out where the problem is if we have a:
ERROR in C:/.../src/$$_gendir/app/app.module.ngfactory.ts (159,52): Supplied parameters do not match any signature of call target.
??? Can we somehow keep the $$_gendir around? Is there some log file that it spits out? I have no clue what it is complaining about and I've spent about 5 hours looking through all the code and there is a lot of it.
i have error like this
ng -v
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | ' \ / _ | | | | |/ _ | '| | | | | | |
/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@angular/cli: 1.4.3
node: 7.10.1
os: linux x64
@angular/animations: error
@angular/common: error
@angular/compiler: 4.4.4
@angular/core: error
@angular/forms: error
@angular/http: error
@angular/platform-browser: error
@angular/platform-browser-dynamic: error
@angular/router: error
@angular/cli: error
@angular/compiler-cli: 4.4.4
@angular/language-service: error
typescript: 2.0.10
how to solve this error package.json:
"dependencies": { "@angular/animations": "^4.0.0", "@angular/common": "^4.0.0", "@angular/compiler": "^4.0.0", "@angular/core": "^4.0.0", "@angular/forms": "^4.0.0", "@angular/http": "^4.0.0", "@angular/platform-browser": "^4.0.0", "@angular/platform-browser-dynamic": "^4.0.0", "@angular/router": "^4.0.0", "bootstrap": "^3.3.7", "core-js": "^2.4.1", "rxjs": "^5.1.0", "zone.js": "^0.8.4" }, "devDependencies": { "@angular/cli": "^1.2.0", "@angular/compiler-cli": "^4.0.0", "@angular/language-service": "^4.0.0", "@types/jasmine": "2.5.45", "@types/node": "~6.0.60", "codelyzer": "~3.0.1", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": "~4.1.0", "karma": "~1.7.0", "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.1.2", "ts-node": "~3.0.4", "tslint": "~5.3.2", "typescript": "~2.0.0" }
For anyone stuck on an old version of Angular and winds up here with this issue: we worked around it by adding a fake build step to our unit tests. In our workflow, this will throw the error before a push, or at the worst throw the error on the test step before it gets all the way to the production build.
Something like this (package.json):
"scripts": {
...
"fake-build": "ng build --prod --aot --target=production",
...
"test": "npm run fake-build && ng test --browsers ChromeHeadless --single-run",
...
},
This does make running the unit tests much slower, but at least stops the embarrassment of a surprise breaking of the production build.
The issue in my case was that My component was running, Stopped it and ran " ng build --prod --aot" and it worked.
help I have a problem problem mark me this error when I put the command ng build --prod
Date: 2019-06-26T19:47:29.429Z Hash: 47649eb13e262d7eaef3 Time: 45551ms chunk {0} runtime-es5.741402d1d47331ce975c.js (runtime) 1.41 kB [entry] [rendered] chunk {1} main-es5.7c04bb8524a34ea08589.js (main) 828 kB [initial] [rendered] chunk {2} polyfills-es5.b8d6dd293b73bbb8581d.js (polyfills) 132 kB [initial] [rendered] chunk {scripts} scripts.000eefc49a6f20ab379c.js (scripts) 607 kB [entry] [rendered]
ERROR in scripts.000eefc49a6f20ab379c.js from Terser Unexpected character '@' [scripts.000eefc49a6f20ab379c.js:17652,1]
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.