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

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

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