javascript - Node.js Babel build and npm module-alias -


i'm using module-alias node.js + express.js project, running babel es2015 support.

app works perfect when started babel-node, however, if first build babel (from package.json):

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

and start:

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

it cannot find correct path specified module-alias. instead of looking app_dist, node.js searches import in app, finds es2015 import directive not understand , throws:

syntaxerror: unexpected token import

if change aliases before start of build, app app_dist, works, question is, how map aliases (or how use different _modulealiases configuration) app resolves paths correctly on development , production?

maybe there way alias modules such stack? in advance.

found solution issue.

in order set relative path aliases module-alias, shoul defined not in package.json, in javascript file inside root directory transpiled babel.

in case, creating aliases.js script inside config directory this:

import path 'path'; import modulealias 'module-alias';  modulealias.addalias('@root', path.resolve(__dirname, '../../')); 

will result in path resolving relatively current working directory, solving described problem.


Comments