Angular ng build give me an error

ng build --prod error
ng build --prod fails
angular build-optimizer
ng build --prod ignore errors
ng build --prod not working angular 8
ng build --watch
ng serve works but build fails
angular outputhashing

I have a small app in Angular 5 and when I try to run build prod ng build --prod, I get this error:

Time: 4739ms
chunk {0} styles.c716146007b500deaef3.bundle.css (styles) 175 kB [initial] [rendered]
chunk {1} polyfills.997d8cc03812de50ae67.bundle.js (polyfills) 84 bytes [initial] [rendered]
chunk {2} main.ee32620ecd1edff94184.bundle.js (main) 84 bytes [initial] [rendered]
chunk {3} inline.318b50c57b4eba3d437b.bundle.js (inline) 796 bytes [entry] [rendered]

ERROR in : Can't resolve all parameters for DataService in .../src/app/services/data.service.ts: (?, [object Object]).

For me this is a big surprise, because in normal, default way the app it's run correctly. I investigate other similar errors and it seems to be from dependencies.

But the big question is, how it's possible to run ok in normal mode, and give me this error just when I run build?!

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';

import { AppError } from '../common/app-error';
import { NotFoundError } from '../common/not-found-error';
import { BadInput } from '../common/bad-input';

@Injectable()
export class DataService {

    constructor(public url: string, private http: HttpClient) { }

    getAll() {
        return this.http
                   .get(this.url)
                   .catch(this.handleError);
    }

    create(resource) {
        return this.http
                   .post(this.url, JSON.stringify(resource))
                   .catch(this.handleError)
    }

    update(resource) {
        return  this.http
                    .patch(`${this.url}/${resource.id}`, JSON.stringify({ isRead: true}))
                    .catch(this.handleError);
    }

    delete(id) {
        return this.http
                   .delete(`${this.url}/${id}`)
                   .catch(this.handleError);
    }

    private handleError(error: Response) {

        if(error.status === 400) {
            return Observable.throw( new BadInput(error));
        }
        if(error.status === 404) {
            return Observable.throw(new NotFoundError());
        }
        return Observable.throw(new AppError(error))

    }

}

And is used:

import { DataService } from './data.service';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable()
export class GithubFollowersService extends DataService {

  constructor(http: HttpClient) {
    super('https://api.github.com/users/mosh-hamedani/followers', http);
  }
}

.. and:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { DataService } from './data.service';

@Injectable()
export class PostService extends DataService {

    // private url: string = 'https://jsonplaceholder.typicode.com/posts';

    constructor(http: HttpClient) {
        super('https://jsonplaceholder.typicode.com/posts', http);
    }

}

I think the issue might be due to the injection of url in your constructor() {}. This might provide a fix:

data.service.ts

import { Router } from '@angular/router';

constructor(private: router: Router, private http: HttpClient) {}

Wherever this.url is called, replace it with this.router.url

New version of cli `ng build --prod` gives error. · Issue #5733 , @angular/cli: 1.0.0-rc.2 node: 7.6.0 os: linux x64 @angular/cli: ng build -prod is giving me ~400's of errors like this, which I do NOT get in ng  The ng build process was throwing out all the errors with references to the line numbers so once I'd worked my way through them I assumed it was all sorted.

If your angular version is 4 or greater, instead of using HttpClient, try using:

import { Http } from '@angular/http';

Angular ng build give me an error, I think the issue might be due to the injection of url in your constructor() {} . This might provide a fix: data.service.ts import { Router } from  @kara: angular-cli: 1.0.0-beta.2-mobile.4 builds OK.. It has issues removing folders which it has emptied. It also will build the main.js in the wrong order once the project gets complicated.

I solve the problem with this:

I remove @Injectable decorator from DataService

@Injectable() //remove it export class DataService { ... }

And from app.modules.ts, I also remove DataService from providers: []

providers[ ... DataService //was removed ... ]

The constructor don't have an injectable parameter (url: string). And this was solve my problems.

Thanks for all ideas!!!

ng build, Compiles an Angular app into an output directory named dist/ at the given output path. Must be executed ng build < project > [ options ] warning|error|ignore. jQuery UI Widgets › Forums › Angular › ng build –prod doesn't work This topic contains 5 replies, has 3 voices, and was last updated by Ivo Zhulev 2 years, 2 months ago . Viewing 6 posts - 1 through 6 (of 6 total)

ng lint, Angular is a platform for building mobile and desktop web applications. Join the Runs linting tools on Angular app code in a given project folder. ng lint  Any help you could give me on the matter would be much appreciated ! ** EDIT ** Ok so one of my colleagues found the issue - we had the same data {{ document.name_fr }} in a mat-tooltip and for some reason that was causing the bug.

Toolips ng build –prod error, Would you mind give me some suggestion on this? Thanks. my environment is: Angular CLI: 1.5.5. Node: 6.11.3. OS: win32 x64. Angular: 5.0.5 animations  Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Angular `ng build --prod` Error - cloud native: the gathering, When building with --prod you see this unhelpful error: 'Unexpected value ng build --prod What is the best IDE for developing in Golang? Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular.

Comments
  • provide code where you use the DataService
  • I added, where is used.
  • No, is not. I added where is used, must be a string.
  • The docs say that this.router.url should return a string: angular.io/api/router/Router#url. If changed in data.service.ts, does it not work?
  • No, the url must be like this: "super('jsonplaceholder.typicode.com/posts', http);"
  • I not url from router.
  • HttpClient was introduced for Angular 4 +