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

232
Visualizações
import fs module: uncaught typeerror

I am trying to use node module in my typescript code, however I get this error: Uncaught TypeError: Failed to resolve module specifier "fs". Relative references must start with either "/", "./", or "../". I have looked the previous posts on stackflow and tried updating my tscofig.json file. I have tried importing it as:

import * as fs from "fs";
const fs = require('fs');

However, both results in the runtime error. Here is my tsconfig.json file:

{
  "compilerOptions": {
     "target": "es5",  
      "module": "ES6",  
      "rootDir": "./src",
      "outDir": "./dist" 
    }
}  

Would be great it someone can guide me towards the cause of the error and possible solutions。

P.S. I have tried reinstalling node modules using npm install --save @types/node

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Change tsconfig.json like

{
  "compilerOptions": {
    "target": "es2017",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "module": "commonjs",                                /* Specify what module code is generated. */
    "rootDir": "./src",                                  /* Specify the root folder within your source files. */
    "moduleResolution": "node",                       /* Specify how TypeScript looks up a file from a given module specifier. */
    "outDir": "./dist",                                   /* Specify an output folder for all emitted files. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  }
}
about 4 years ago · Juan Pablo Isaza 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