digitalascetic / ngx-pica

@digitalascetic/ngx-pica is an Angular(LTS) module to resize images files in browse
36 stars 26 forks source link

Error with exif.js (assignment to undeclared variable n) #26

Closed nicolaspernoud closed 4 years ago

nicolaspernoud commented 5 years ago

After creating a brand new project with ng new installing ngx-pica and creating a component with the example code provided in the readme.md, I get an error :

ERROR ReferenceError: "assignment to undeclared variable n"
    getStringFromDB exif.js:741
    readEXIFData exif.js:748
    findEXIFinJPEG exif.js:449
    handleBinaryFile exif.js:370
    onload exif.js:391
    Angular 5

Package.json is below :

{
  "name": "pica-test",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.0",
    "@angular/cdk": "~8.2.0",
    "@angular/common": "~8.2.0",
    "@angular/compiler": "~8.2.0",
    "@angular/core": "~8.2.0",
    "@angular/forms": "~8.2.0",
    "@angular/material": "^8.2.0",
    "@angular/platform-browser": "~8.2.0",
    "@angular/platform-browser-dynamic": "~8.2.0",
    "@angular/router": "~8.2.0",
    "@digitalascetic/ngx-pica": "^8.0.1",
    "exif-js": "^2.3.0",
    "hammerjs": "^2.0.8",
    "pica": "^5.1.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.802.2",
    "@angular/cli": "~8.2.2",
    "@angular/compiler-cli": "~8.2.0",
    "@angular/language-service": "~8.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}
nicolaspernoud commented 4 years ago

I retried with an even simpler project (no material), and the problem was the same (on firefox 69 and MS Edge).

Error stack : "ReferenceError: Variable undefined in strict mode at getStringFromDB (http://localhost:4200/vendor.js:83609:14) at readEXIFData (http://localhost:4200/vendor.js:83616:9) at findEXIFinJPEG (http://localhost:4200/vendor.js:83317:17) at handleBinaryFile (http://localhost:4200/vendor.js:83238:13) at fileReader.onload (http://localhost:4200/vendor.js:83259:21) at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:3593:13) at onInvoke (http://localhost:4200/vendor.js:70641:17) at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:3593:13) at Zone.prototype.runGuarded (http://localhost:4200/polyfills.js:3369:21) at Anonymous function (http://localhost:4200/polyfills.js:3353:17)"

Could someone have a look ?

home.component.ts :

import { Component, EventEmitter } from '@angular/core';
import { NgxPicaService, NgxPicaErrorInterface } from '@digitalascetic/ngx-pica';

@Component({
  selector: 'app-home',
  template: `
      <img *ngFor="let image of images" [src]="image" />

      <input type="file" accept="image/png, image/jpeg" multiple
             (change)="handleFiles($event)">
  `
})
export class AppHomeComponent {
    images: File[] = [];

    constructor(private _ngxPicaService: NgxPicaService) {

    }

    public handleFiles(event: any) {
        const files: File[] = event.target.files;

        this._ngxPicaService.resizeImages(files, 1200, 880)
            .subscribe((imageResized: File) => {
                let reader: FileReader = new FileReader();

                reader.addEventListener('load', (event: any) => {
                    this.images.push(event.target.result);
                }, false);

                reader.readAsDataURL(imageResized);

            }, (err: NgxPicaErrorInterface) => {
                throw err.err;
            });
    }
  }

package.json :

{
  "name": "pica-test",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.4",
    "@angular/common": "~8.2.4",
    "@angular/compiler": "~8.2.4",
    "@angular/core": "~8.2.4",
    "@angular/forms": "~8.2.4",
    "@angular/platform-browser": "~8.2.4",
    "@angular/platform-browser-dynamic": "~8.2.4",
    "@angular/router": "~8.2.4",
    "@digitalascetic/ngx-pica": "^8.0.2",
    "exif-js": "^2.3.0",
    "pica": "^5.1.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.2",
    "@angular/cli": "~8.3.2",
    "@angular/compiler-cli": "~8.2.4",
    "@angular/language-service": "~8.2.4",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

Install sequence :

ng new pica-test
npm install @digitalascetic/ngx-pica --save
npm install pica@^5.1.0
npm install exif-js@^2.3.0
nicolaspernoud commented 4 years ago

It was a strange exif-js problem. The 2.3.0 release is flawed on npm. This fixed it : npm install https://github.com/exif-js/exif-js instead of npm install exif-js... The error is at line 741 of exif.js (for (var n = start; n < start+length; n++) {)

yutthagarn commented 4 years ago

It was a strange exif-js problem. The 2.3.0 release is flawed on npm. This fixed it : npm install https://github.com/exif-js/exif-js instead of npm install exif-js... The error is at line 741 of exif.js (for (var n = start; n < start+length; n++) {)

Thanks. It's work.