adamhalasz / uniqid

Unique ID Generator
https://adamhalasz.com
617 stars 49 forks source link

"Missing initializer in const declaration" caused when building minified bundle. #23

Open mohit-jasapara opened 6 years ago

mohit-jasapara commented 6 years ago

Missing initializer in const declaration error when creating minified build

const networkInterface,length;

Solution: Replace

if(typeof __webpack_require__ !== 'function'){
    var mac = '', networkInterfaces = require('os').networkInterfaces();
    for(interface_key in networkInterfaces){
        var networkInterface = networkInterfaces[interface_key];
        var length = networkInterface.length;
        for(var i = 0; i < length; i++){
            if(networkInterface[i].mac && networkInterface[i].mac != '00:00:00:00:00:00'){
                mac = networkInterface[i].mac; break;
            }
        }
    }
    address = mac ? parseInt(mac.replace(/\:|\D+/gi, '')).toString(36) : '' ;
}

const networkInterface -> var networkInterface const length -> var length

fgeorgsson commented 5 years ago

When running a unit test in Jest that uses uniqid the same problem appears:

Test suite failed to run

    ReferenceError: interface_key is not defined

    > 6 | const uniqid = require('uniqid');
darrylsepeda commented 5 years ago

I encounter this error when I run test in Jest also, is there any solution yet regarding this issue?

@mohit-jasapara , does your solution need to be applied on the minified bundle or on uniqid source code before minified?