Angular 未能编译:./node_modules/macaddress/lib/windows.js(位于5中)
我是Angular 5的新手,根据我的业务需要,我需要获得用户机器的mac地址 参考: 我已经在我的typescript文件中使用NPM和以下代码添加了这个包Angular 未能编译:./node_modules/macaddress/lib/windows.js(位于5中),angular,typescript,angular5,Angular,Typescript,Angular5,我是Angular 5的新手,根据我的业务需要,我需要获得用户机器的mac地址 参考: 我已经在我的typescript文件中使用NPM和以下代码添加了这个包 var macaddress = require('macaddress'); //added this code below my imports ngOnInit() { macaddress.one(function (err, mac) { console.log("Mac address for thi
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);
});
}
添加这些代码后,我无法运行我的项目,它会显示一个带有上述错误的黑屏
谁能帮我修一下这个吗
编辑:./node_modules/macaddress/lib/windows.js
未找到模块:错误:无法解析“D:\Projects\Angular\eCommerceWebsite\node\u modules\macaddress\lib”中的“子进程”
错误@vendor.js:158535
把这个放在控制台里
更新:
这是在应用程序模块文件app.module.ts中添加模块的示例,例如“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 { }
这是在应用程序模块文件app.module.ts中添加模块的示例,例如“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 { }
无法从Angular应用程序使用此库。出于安全原因,您根本无法从浏览器查询用户的mac地址。该库用于服务器端node.js应用程序,与任何客户端应用程序无关。
您不能从Angular应用程序使用此库。出于安全原因,您根本无法从浏览器查询用户的mac地址。该库用于服务器端node.js应用程序,与任何客户端应用程序无关。
能否检查浏览器控制台上显示的错误?请检查更新的post@SandeepkaMath是否已导入正在类型脚本文件中使用的新模块。能否添加typescript文件的代码段?我正在app.component.ts文件中使用此代码。@SandeepKamathok。基本上,您需要在AppModules类中添加一个新模块,然后导入组件ts文件。请在下面的代码段中找到一个示例。您可以检查浏览器控制台上显示的错误吗?请检查更新的post@sandeepkamath是否已导入您在类型脚本文件中使用的新模块。能否添加typescript文件的代码段?我正在app.component.ts文件中使用此代码。@SandeepKamathok。基本上,您需要在AppModules类中添加一个新模块,然后导入组件ts文件。请在下面的代码段中找到一个示例,我认为这是因为它只是npm代码。但是在你安装npm之后,你能在你的ng_modules文件夹中看到macaddress模块吗?是的,我有。我真的很困惑,所有的文件都在那里,但不工作,请查看更新post@Sandeepkamathyes然后,如果您使用VisualStudio代码。如果尚未在app.module.ts文件中添加模块,您将获得添加模块的选项。正如我在示例“BrowerModule”中所给出的那样,我应该如何使其工作,请给出一个解决方案,兄弟,我正在与这个@SandepKamath1进行斗争。首先,我认为您需要在app.module.ts文件中添加与BrowserModule相同的模块。2.然后在app.component.ts中导入模块,如果你做到以上两点,它应该可以工作。我认为这是因为它只是npm代码。但是在你安装npm之后,你能在你的ng_modules文件夹中看到macaddress模块吗?是的,我有。我真的很困惑,所有的文件都在那里,但不工作,请查看更新post@Sandeepkamathyes然后,如果您使用VisualStudio代码。如果尚未在app.module.ts文件中添加模块,您将获得添加模块的选项。正如我在示例“BrowerModule”中所给出的那样,我应该如何使其工作,请给出一个解决方案,兄弟,我正在与这个@SandepKamath1进行斗争。首先,我认为您需要在app.module.ts文件中添加与BrowserModule相同的模块。2.然后在app.component.ts中导入模块,如果您执行上述两点操作,那么它应该可以工作。那么,是否有任何方法可以通过系统的任何唯一标识来识别每个用户。请指导我@VahidNSo是否有任何方法可以通过系统的任何唯一标识来识别每个用户。请指导我@VahidN