Failed to compile : ./node_modules/macaddress/lib/windows.js in Angular 5
Asked Answered
N

2

0

I am new to Angular 5 ,as per my business need I need to get the user machine's mac address.For that I tried to implement the following...

enter image description here

Reference: https://www.npmjs.com/package/macaddress

npm install --save macaddress

I have added this package using NPM and the following code in my typescript file .

var macaddress = require('macaddress'); //added this code below my imports

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

After adding this codes I can't run my project and it showing a black screen with the above error .

Can anyone help me to fix this please.

Edit : ./node_modules/macaddress/lib/windows.js Module not found: Error: Can't resolve 'child_process' in 'D:\Projects\Angular\eCommerceWebsite\node_modules\macaddress\lib' errors @ vendor.js:158535

got this in console.

Update :

enter image description here

Northamptonshire answered 9/9, 2018 at 6:3 Comment(6)
can you check the error that is displaying on the console of your browser ?Knapsack
please check the updated post @SandeepKamathNorthamptonshire
have you imported the new module that you are using in the type script file. Can you please add the code snippet of the your typescript file ?Knapsack
I am using this code in my app.component.ts file .@SandeepKamathNorthamptonshire
ok. basically you need to add an new module in app modules class and then import in component ts file. Please find an example in the below code snippetKnapsack
I have registered the app component in modules.ts file . code snippet ? @SandeepKamathNorthamptonshire
G
3

You can't use this library from an Angular app. You can't query the user's mac address from a browser at all for security reasons. That library is intended for server-side node.js apps and has nothing to do with any client-side app's. More info here

Gothurd answered 10/9, 2018 at 13:48 Comment(1)
So is there any way to identify each user by any unique identity of the system .please guide me @GothurdNorthamptonshire
K
-1

This is an example of adding a module in app module file app.module.ts for example 'BrowserModule'

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';

@NgModule({
 imports:      [ BrowserModule ],
 declarations: [ AppComponent ],
 bootstrap:    [ AppComponent ]
})
export class AppModule { }
Knapsack answered 9/9, 2018 at 7:27 Comment(6)
I think that is because it just npm code. But after you do npm install , are you able to see macaddress module inside your ng_modules folder ?Knapsack
yes I have it . I am really confused all the files are there but not working please see the updated post@SandeepkamathNorthamptonshire
yes then if you use Visual Studio Code. you will get options of adding the module, if you have not added the module in app.module.ts file. as given in the example by me for example 'BrowerModule'Knapsack
So what should I do to make it work ,please give a solution brother I am really struggling with this @SandeepKamathNorthamptonshire
1. first i think you need to add the module in app.module.ts file same as that of BrowserModule. 2. Then import the module in your app.component.ts if you do this above two point it should work.Knapsack
I can’t find any module name I tried to type getmac and Macaddress but there I cannot find anything like that ....@SandeepKamathNorthamptonshire

© 2022 - 2024 — McMap. All rights reserved.