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

679
Visualizações
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 Respostas
Responde à pergunta

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