Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

422
Visualizações
Cannot import module 'os' in Electron

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!!

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

I didn't read his question properly.

the commenter is right you cannot import os to do this on an angular client side application.

instead it should be no imports and you can access via the document, or the window.

USING DOCUMENT

document.location.hostname

or

USING WINDOW

 window.location.hostname
over 4 years ago · Santiago Trujillo Relatório

0

this is rather unbelievable but without ActiveX controls it won't work and even then it will work very little because almost all windows based pc's have this disabled by default I believe.

its easy to get the client IP address - but this gets incredibly complex. You can try http interceptor but that seemed like it was half baked based upon the three hours of my life I dedicated to this. I'm rather dumb founded to be honest.

over 4 years ago · Santiago Trujillo Relatório

0

The correct code is

import * as os from 'os';

Usage example :

const hostname = os.hostname();
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda