1

I am new to Angular ,Here in my project I need to get the MAC address of the user's system .

For that I have executed a NPM as follows

npm install --save macaddress

Added the below code after the imports in my app.component.ts file

var macaddress = require('macaddress');

And this in my ngOnInit

 macaddress.one(function (err, mac) {
            console.log("Mac address for this host: %s", mac);  
          });

After adding all these code and I tried to Serve the project but I got the below error .

ERROR in ./node_modules/macaddress/lib/windows.js
Module not found: Error: Can't resolve 'child_process' in 'D:\Projects\Angular\eCommerceWebsite\node_modules\macaddress\lib'
ERROR in ./node_modules/macaddress/lib/unix.js
Module not found: Error: Can't resolve 'child_process' in 'D:\Projects\Angular\eCommerceWebsite\node_modules\macaddress\lib'
ERROR in ./node_modules/macaddress/lib/linux.js
Module not found: Error: Can't resolve 'child_process' in 'D:\Projects\Angular\eCommerceWebsite\node_modules\macaddress\lib'
ERROR in ./node_modules/macaddress/index.js
Module not found: Error: Can't resolve 'os' in 'D:\Projects\Angular\eCommerceWebsite\node_modules\macaddress'

After executed the npm install --save macaddress I executed the npm install -g

But I can't solve this error ,Can anyone help me to solve this please.

Zhu
  • 3,679
  • 14
  • 45
  • 76

1 Answers1

0

It seems that the package macaddress makes usage of child_process module which is only available in the context of Node.js.

Angular runs in the browser and does not have access to the hardware address as well as the module child_process.

Please see the following link for more informations and workarounds: How to get client MAC address by a access on a website?

Hope this information was helpful.

Regards

Fleditor
  • 90
  • 2