How to generate a build (production) of an angular project?

Asked

Viewed 2,032 times

0

I’m trying to generate the build of an Angular project, but every time I turn the command to it ng build is presented me several errors, but searching I could not solve, someone would have a light?

E:\Sistemas\sourcecode>ng build --source-map=false --prod --deploy-url=client/

Date: 2019-01-09T17:29:00.855Z
Hash: 00b6ba86f5c09a5273e8
Time: 121743ms
chunk {0} runtime.8004edb872d7c3b82213.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main.9868d9b237c3a48c54da.js (main) 128 bytes [initial] [rendered]
chunk {2} polyfills.85f47f0bf59079cbc23a.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} styles.0befdcbdc7f0c4753cdc.css (styles) 75.2 kB [initial] [rendered]

ERROR in src/common/uploads/utils/upload-progress-event.ts(47,17): error TS2322: Type 'HttpEventType.UploadProgress | HttpEventType.DownloadProgress' is not assignable to type 'HttpEventType.Sent | HttpEventType.UploadProgress | HttpEventType.Response'.
  Type 'HttpEventType.DownloadProgress' is not assignable to type 'HttpEventType.Sent | HttpEventType.UploadProgress | HttpEventType.Response'.
src/common/uploads/uploaded-file.ts(19,34): error TS2339: Property 'webkitRelativePath' does not exist on type 'File'.
src/common/uploads/uploaded-file.ts(27,25): error TS2345: Argument of type 'string | ArrayBuffer' is not assignable to parameter of type 'string | PromiseLike<string>'.
  Type 'ArrayBuffer' is not assignable to type 'string | PromiseLike<string>'.
    Type 'ArrayBuffer' is not assignable to type 'string'.
src/common/uploads/utils/create-upload-input.ts(31,15): error TS2339: Property 'webkitdirectory' does not exist on type 'HTMLInputElement'.
src/common/uploads/utils/read-uploaded-folders.ts(3,52): error TS2304: Cannot find name 'WebKitEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(10,58): error TS2304: Cannot find name 'WebKitFileEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(12,66): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(19,40): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(26,50): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(28,63): error TS2304: Cannot find name 'WebKitFileEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(35,27): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(35,58): error TS2304: Cannot find name 'WebKitEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(42,36): error TS2304: Cannot find name 'WebKitFileEntry'.

Here is my tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "common": [
        "common/"
      ]
    },
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

And here’s my read-uploaded-folders.ts

import { UploadedFile } from '../uploaded-file';

export async function readUploadedFolders(entries: WebKitEntry[]): Promise<UploadedFile[]> {
    let files = [];

    for (const key in entries) {
        const entry = entries[key];

        if ( ! entry.isDirectory) {
            files.push(await transformFileEntry(entry as WebKitFileEntry));
        } else {
            files = files.concat(await readDirRecursive(entry as WebKitDirectoryEntry));
        }
    }

    return files;
}

async function readDirRecursive(entry: WebKitDirectoryEntry, files = []) {
    const entries = await readEntries(entry);

    for (const key in entries) {
        const childEntry = entries[key];

        if (childEntry.isDirectory) {
            await readDirRecursive(childEntry as WebKitDirectoryEntry, files);
        } else {
            files.push(await transformFileEntry(childEntry as WebKitFileEntry));
        }
    }

    return files;
}

function readEntries(dir: WebKitDirectoryEntry): Promise<WebKitEntry[]> {
    return new Promise(resolve => {
        const reader = dir.createReader();
        reader.readEntries(entries => resolve(entries as any));
    });
}

function transformFileEntry(entry: WebKitFileEntry) {
    return new Promise(resolve => {
        entry.file((file: any) => {
            resolve(new UploadedFile(file as File, entry.fullPath));
        });
    });
}

File upload-Progress-Event.ts

import { HttpEvent, HttpEventType } from '@angular/common/http';
import { getUploadProgress } from './get-upload-progress';
import { getUploadSpeed } from './get-upload-speed';
import { getUploadETA } from './get-upload-eta';
import { prettyUploadETA } from './pretty-upload-eta';
import { prettyBytes } from '../../core/utils/pretty-bytes';
import { FileEntry } from '../file-entry';
import { BackendResponse } from '../../core/types/backend-response';

export enum UploadEventTypes {
    STARTED = 'uploadStarted',
    PROGRESS = 'uploadProgress',
    COMPLETED = 'uploadCompleted',
    OTHER = 'unrecognizedEvent'
}

export interface UploadCompletedEvent {
    type: HttpEventType.Response;
    name: UploadEventTypes.COMPLETED;
    fileEntry: FileEntry;
}

export interface UploadProgressEvent {
    type: HttpEventType.UploadProgress;
    name: UploadEventTypes.PROGRESS;
    totalBytes: number;
    completedBytes: number;
    progress: number;
    speed: string;
    eta: string;
}

export interface UploadStartedEvent {
    type: HttpEventType.Sent;
    name: UploadEventTypes.STARTED;
    time: number;
}

export type UploadEvent = UploadStartedEvent | UploadCompletedEvent | UploadProgressEvent;

export function transformAngularUploadEvent<T>(e: HttpEvent<{fileEntry: FileEntry}>, uploadStarted: number): UploadEvent {
    switch (e.type) {
        case HttpEventType.Sent:
            return {type: e.type, name: UploadEventTypes.STARTED, time: uploadStarted};
        case HttpEventType.UploadProgress:
            return {
                type: e.type,
                name: UploadEventTypes.PROGRESS,
                totalBytes: e.total,
                completedBytes: e.loaded,
                progress: getUploadProgress(e),
                speed: prettyBytes(getUploadSpeed(e, uploadStarted)),
                eta: prettyUploadETA(getUploadETA(e, uploadStarted)),
            };
        case HttpEventType.Response:
            return {type: e.type, name: UploadEventTypes.COMPLETED, fileEntry: e.body.fileEntry};
        default:
            return null;
    }
}
  • 1

    There seem to be errors in the files src/common/uploads/utils/upload-progress-event.ts, src/common/uploads/uploaded-file.ts, src/common/uploads/utils/create-upload-input.ts and src/common/uploads/utils/read-uploaded-folders.ts. Have you read the error message? From the second blank line down there is the description of the file, row, column and details of what is wrong.

  • Apparently there is no error in the Anderson file! These Webkit are dependencies of the Typescript package, both the TS2304 error, but the package is installed as well!

  • Try adding the flag --no-aot when compiling, I do not remember what it does, but for me it solved

  • Did not happen @edsonalves error remained using flag! :(

  • Appears to be a same code error: ERROR in src/common/uploads/utils/upload-Progress-Event.ts(47,17) on this file and on this line.

  • The type of HttpEvent<{fileEntry: FileEntry}> cannot be included in type of UploadEvent which is the return object of line 47, 17 of the file upload-Progress-Event.ts

Show 1 more comment

1 answer

-1

I do it this way:

I have two files environments, in the .angular-cli.json

 "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
 }

they reference two files where I place my local urls and the other the production/homologation urls

Ex: Local class

export const environment = {
   apiUrl: 'http://localhost:8080',
   urlImagens: 'http://localhost:8080'
};

And in the other I just change these local addresses by homologous addresses

In the terminal just put the command ng build --prod or ng build --dev

Prod and dev were the names I defined in .angular-cli.json

Browser other questions tagged

You are not signed in. Login or sign up in order to post.