Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

420
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

The correct code is

import * as os from 'os';

Usage example :

const hostname = os.hostname();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda