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

229
Vistas
Cannot import router from file with ES6 import/export?

I am converting my whole node app to use the ES6 syntax import NME from "./file"

In my app.js file I am trying to import my routers but am getting the error "Cannot find module '/Users/app/git/app-node-api/src/routers/availability' imported from /Users/app/git/app-node-api/src/app.js"

This was working perfectly fine before using the require statements but since I am new to using the import for modules, something has messed up.

Why is this not working? I tried different export syntax's like export { router } but it didn't work?

My current import/export from files looks like below...

APP.JS

import express from "express"
import("./db/mongoose")
const app = express()

import availabilityRouter from "./routers/availability"
// ^ CANNOT FIND MODULE "/Users/app/git/app-node-api/src/routers/availability" ?

module.exports = app 

AVAILABILITY.JS

import express from "express"
const router = new express.Router()

router.get(`/verify/email/:email`, async (req, res) => {
  // DO STUFF
})

router.get(`/verify/username/:username`, async (req, res) => {
  // DO STUFF
})

module.exports = router // AM I EXPORTING CORRECTLY??

PACKAGE.JSON

{
  "name": "app-api",
  "version": "1.0.0",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "start": "nodemon src/index.js",
    "dev": "env-cmd -f ./config/dev.env nodemon src/index.js -e js,hbs",
    "prod": "env-cmd -f ./config/prod.env nodemon src/index.js",
    "test": "env-cmd -f ./config/test.env nodemon --exec 'mocha -R min'",
    "deploy": "make this auto deploy code to ec2 instance"
  },
  "license": "ISC",
  "dependencies": {
   ////
}
}

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

module.exports commonjs syntax.

try this for ES6

export default router;
about 4 years ago · Santiago Gelvez 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