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

335
Vistas
How can i use requier and import statments in node js , at the same file

my problem when i was working on my node js file , is that im importing readline statments , and using ( 'type': 'module' ) at the same time , wanting to use both ways while no errors how can i use requier on ( readline ) command ?
the type of error im facing is :

SyntaxError: Cannot use import statement outside a module

i tried to use module on ( packag.json) but then the requier statment will face type error i couldnt ( transfare) (import readline, { clearScreenDown } from "readline"; ) as an a requier statement like this (const db = require('./dbConnection');)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can't, they're mutually-exclusive. import is ESM (JavaScript's native, specified module system), and require is CommonJS (Node.js's older module system).

Instead, you have to use ESM or CommonJS consistently.

If you need to do a dynamic (runtime-determined) import in ESM, you can use the import() pseudo-function, which is a bit like CommonJS require except that rather than making the calling code wait, it returns a promise.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Answer depends on the choice of method you want to use.

  1. Use import ABC from 'ABC' (node core module or packages downloaded via npm)
  2. User const abc = require('./ABC') for your custom modules. below are examples.

ABC.js

const ABC = ()=> {
 return "ABC is called";
}
module.exports=ABC;

now in file you want to call it. index.js

const abc = require('./ABC');
about 4 years ago · Juan Pablo Isaza 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