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

392
Vistas
The requested module does not provide an export named default via express routing

I'm in the need of assistance on finding what exactly i'm missing here.

If it helps, my app is on node.js (16.13.1) using the latest version of express as well as a nginx reverse proxy.

app.mjs

import router from './assets/js/router.mjs'; //Imports our routes 

import express from 'express';

const expressapp = express(); //Creates the application with express

const moduleURL = new URL(import.meta.url); //Creates a new URL to use for the current directory name

const __dirname = path.dirname(moduleURL.pathname); //Creates the directory name and attaches it to the __dirname constant.

//Middleware

//Instructions for the app to use body parser & JSON goes here

expressapp.use('/subscribe', router); //Use the subscribe route

expressapp.use(express.static(__dirname, {index: 'index.html'})); //Tells the app to use the current path, with the index being index.html

expressapp.post('/subscribe', (req, res) => 
{
   //post request stuff goes here
}

router.mjs

import express from 'express';

var router = express.Router();

// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
  console.log('Time: ', Date.now())
  next()
})
// define the home page route
router.get('/', function (req, res) {
  res.send('Gaming Galaxy Landing Page')
})

// define the subscribe route
router.get('/subscribe', function (req, res) {
  res.send('Subscribe route')
})

export default router;

Error

import router from './assets/js/router.mjs'; //Imports our routes
       ^^^^^^
SyntaxError: The requested module './assets/js/router.mjs' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

As someone who's somewhat new to this stuff, I really don't know what's wrong when I specifically defined a default export in my router. If anyone could help me learn what exactly is going on here it'll be very much appreciated

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

0

I think u have forgotten to save router.mjs file as I did the same mistake and got this error :)

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