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

288
Vistas
Node.js Babel build and npm module-alias

I'm using module-alias for my Node.js + Express.js project, running it with Babel for ES2015 support.

App works perfect when started with babel-node, however, if I first build it with babel (from package.json):

"build": "babel ./app --out-dir ./app_dist"

And then start:

"start": "node ./app_dist/bin/www"

It obviously cannot find the correct path specified with module-alias. Instead of looking into app_dist, Node.js searches for import in app, finds ES2015 import directive which it does not understand and throws:

SyntaxError: Unexpected token import

If I change aliases before start of that build, from app to app_dist, it works, but the question is, how to map those aliases (or how to use different _moduleAliases configuration) so that app resolves the paths correctly on development and production?

Maybe there is another way to alias modules with such stack? Thanks in advance.

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

0

Found solution for this issue.

In order to set the relative path aliases with module-alias, they shoul be defined not in package.json, but in JavaScript file inside the root directory that will be transpiled with Babel.

In my case, creating an aliases.js script inside config directory like this:

import path from 'path';
import moduleAlias from 'module-alias';

moduleAlias.addAlias('@root', path.resolve(__dirname, '../../'));

Will result in path resolving relatively to the current working directory, solving described problem.

about 4 years ago · Santiago Trujillo 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