angularexif-js

Angular with exif-js only on production mode not work correctly


When I make an ng serve on my project it's work just fine. But when I run ng build --prod --base-href then some problems connected with exif-js will show up.

main-es2015.4f373a513488bb1e69c9.js:40745 ERROR ReferenceError: n is not defined
    at getStringFromDB (main-es2015.4f373a513488bb1e69c9.js:126856)
    at readEXIFData (main-es2015.4f373a513488bb1e69c9.js:126863)
    at findEXIFinJPEG (main-es2015.4f373a513488bb1e69c9.js:126564)
    at handleBinaryFile (main-es2015.4f373a513488bb1e69c9.js:126485)
    at getImageData (main-es2015.4f373a513488bb1e69c9.js:126501)
    at Function.push../node_modules/exif-js/exif.js.EXIF.getData (main-es2015.4f373a513488bb1e69c9.js:127098)
    at ImagesLoadingService.loadExif (main-es2015.4f373a513488bb1e69c9.js:153715)
    at HTMLImageElement.img.onload [as __zone_symbol__ON_PROPERTYload] (main-es2015.4f373a513488bb1e69c9.js:153689)
    at HTMLImageElement.wrapFn (polyfills-es2015.c96fb5427ba53ad92441.js:1201)
    at ZoneDelegate.invokeTask (polyfills-es2015.c96fb5427ba53ad92441.js:403)

I know the error reason is some variable is not defined but why on ng serve it's work correctly?

SOLVED

I find problem in exif.js file:

    function getStringFromDB(buffer, start, length) {
        var outstr = "";
        for (let n = start; n < start+length; n++) { // I add let before n variable and now it's work just fine on prod build
            outstr += String.fromCharCode(buffer.getUint8(n));
        }
        return outstr;
    }

I build project in ng build --prod --base-href --optimization=false to find the problem place. On Firefox I get diffrent error description so I can't find specific place of code. Only on Chrome I get more specific info about that and I can solve my probem. I hope someone else this will help too :)


Solution

  • I find problem in exif.js file:

        function getStringFromDB(buffer, start, length) {
            var outstr = "";
            for (let n = start; n < start+length; n++) { // I add let before n variable and now it's work just fine on prod build
                outstr += String.fromCharCode(buffer.getUint8(n));
            }
            return outstr;
        }
    

    I build project in ng build --prod --base-href --optimization=false to find the problem place. On Firefox I get diffrent error description so I can't find specific place of code. Only on Chrome I get more specific info about that and I can solve my probem. I hope someone else this will help too :)