I am doing an easy test to try to get my computer's name in an Electron app using Angular and nodejs.
This is my script:
import { Component, OnInit } from '@angular/core';
import { hostname } from 'os'
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit(): void {
console.log(hostname);
}
}
I also installed npm i @types/node
I get the following error:
Error: src/app/components/home/home.component.ts:2:26 - error TS2307: Cannot find module 'os' or its corresponding type declarations. import { hostname } from 'os'
Any ideas? this should be straightforward and I feel so silly with such a problem...
Edit: I added that this is an electron app!!
Before using import * as os from 'os';, you have to make sure "types":["node"] in the tsconfig.app.json
{
"compilerOptions": {
"types": [
"node"
]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With