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

688
Vistas
Nestjs: import modules undefined, but methods and functions from modules can be imported

I am using Nestjs with WebStorm & TS 4.2.3^latest.

The problem that I am facing is a bit strange. For example, some modules, like axios can be installed, imported, and used as usual. But some modules, especially Nodejs Core, like fs or path, can't be imported as modules. BUT their methods can be imported and used just fine!

//ERROR: Module undefined on run:dev, but no error in IDE
import path from 'path';
import fs from 'fs';

//Working fine
import { join } from 'path';
import { readFileSync } from 'path';

I am sure, they have correct TS types, even installed manually. For example:

import axios from 'axios';
import path from 'path'; //path is undefined
import { join } from 'path'; // working fine
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  async test(input: string): Promise<void> {
    await axios.get() // working fine

    await path.join() // Cannot read property 'join' of undefined

    //BUT await join() // Works fine!
  }
}

I have only one tsconfig.json which is generated by Nest Cli. I am starting my apps via npm start:dev -name and IDE don't show any errors in code, until I ran code.

Example

tsconfig.json module part, just to be sure: "module": "commonjs", package.json doesn't have module part at all.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

IDE in this case, misdirect me a bit. Almost forgot, that I am dealing with TS now. Some modules seem to have no default exports, so:

  • You should import as with them: import * as fs from 'fs';
  • Or, another option is enabling: "esModuleInterop": true, in your tsconfig.json
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