ilearnio / module-alias

Register aliases of directories and custom module paths in Node
MIT License
1.76k stars 69 forks source link

Problem with babel #84

Open arthabus opened 4 years ago

arthabus commented 4 years ago

Hi, I have the following use case.

I have nodejs app that needs to reuse model hierarchy written in ES6 with all those exports which is not supported in the server's node version (v10). And to make it work I use webpack+bable to transpile only the model-related classes with the structure as below

index.js //app entry point, not webpacked/not transpiled

...
const ObjClass1 = require(./model).ObjClass1
...

model.js//webpack entry point, transpiled with babel, hub for all models that needs to be transiled

import ObjClass1 from "some/path/ObjClass1"
exports.ObjClass1 = ObjClass1
...

Now as soon as I add require('module-alias/register')to the index.js with an alias in package.json (like @root) I'm starting to get the following error in node complaining about model.js:

SyntaxError: Cannot use import statement outside a module

If I remove require('module-alias/register') everything starts to work again.

It seems like the plugin breaks something for babel - do you have any suggestions on how to overcome that?

Kehrlann commented 4 years ago

Hello !

Thanks for reporting. I'm not very familiar with babel, I'm not even sure where to start. Could you please share a minimal project showcasing this problem + instructions, so I can investigate ?

Cheers 👋