adamhalasz / uniqid

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

Error when importing uniqID in vite project #40

Open xiaobeilo opened 3 years ago

xiaobeilo commented 3 years ago

When uniqID is imported into vite, the following error occurs: require_os(...).networkInterfaces is not a function After checking the code, it is because of this code: if(typeof __webpack_require__ !== 'function'){ var mac = '', networkInterfaces = require('os').networkInterfaces(); loop: for(let interface_key in networkInterfaces){ const networkInterface = networkInterfaces[interface_key]; const length = networkInterface.length; for(var i = 0; i < length; i++){ if(networkInterface[i] !== undefined && networkInterface[i].mac && networkInterface[i].mac != '00:00:00:00:00:00'){ mac = networkInterface[i].mac; break loop; } } } address = mac ? parseInt(mac.replace(/\:|\D+/gi, '')).toString(36) : '' ; }

Because __webpack_require__ does not exist in vite, the code that enters it will report an error

adamhalasz commented 3 years ago

@xiaobeilo added vite support in v5.4.0. You can update uniqid now. There's also a vite example in the examples folder. you will need to install the vite dependencies in the vite-project. The example is in the HelloWorld.vue component.

Let me know if this fixes it for you.

xiaobeilo commented 3 years ago

It's working fine! Thanks for the revision!👍