-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
babel doesn't transform ES6 under node_modules #41
Comments
babel-node
doesn't transform ES6 under node_modules
I'm not convinced that babel runtime will address this. |
Modules should be doing their own 6to5 transpiling and providing the compiled "dist" version as the "main" in package.json. It's not this project's (or any other project's) responsibility to compile dependencies to ES5. /2¢ |
@therealklanni, node_modules is used internally for convenience (not for external modules). And node_modules gets ignored. This is a valid point. |
Oh, I misread that as the main |
I personally do not think using node_modules for convenience is a good idea. |
@nkbt Fair critique. It's unconventional. I've been experimenting with it, and in my own project I've moved the structure to a |
Compiling code before running it for backend feels awkward, just need to whitelist internal node_modules for babel. Need to add it to |
@nkbt Is that all there is to it? I agree about the awkwardness. |
@zebulonj I am not 100% sure, of course, but looks like that should be it. |
@nkbt It appears that the |
If that's possible, it's the right solution. Otherwise, I have no problem compiling the internal Of course, we leave the vendor |
You may want to ask the babel team how to handle this before resorting to the pre-compile route. |
Based on past experiences in a project with node modules where we run mocha through babel-node (and after expend a fair amount of time trying to figure out why it didnt transpile... :D) you just need to change the ignore property in the require call, by default is a regexp for /node_modules/, if you change it it will transpile fine: https://babeljs.io/docs/usage/require/ |
Thanks @kileras. This works:
What do you all think? Smell funny? |
Now that we've identified a command-line option that works, it can alternatively be added to the |
better to .babelrc |
Ugh. In the |
Then add to npm scripts if it does not work. And you can file a bug to babel as well... |
Another solution for the same problem (requiring modules from the root) is to use a a custom babel plugin - https://github.com/gavriguy/babel-plugin-project-relative-require as discussed at http://stackoverflow.com/questions/31068698/importing-node-modules-from-root-directory-using-es6-and-babel-node/31069137#31069137 Basically you can use the ~ sign to require modules from the root e.g. |
@gavriguy I don't like the idea of littering the codebase with weird/uncommon babel preprocessors. |
👍 |
What's the status of this issue? |
I got this working following this solution http://stackoverflow.com/questions/31822593/import-a-module-from-node-modules-with-babel-but-failed/31822668#31822668
Since babel-node ignores node_modules by default, this regex will unignore just the module you want to transpile... Although this is not a pattern that the babeljs community wants to encourage, since all npm packages should be transpiled on pre-publish. |
If anybody wants to take a crack at this, I'd appreciate it. It will probably be a couple weeks before I can get back to it. |
Scrapped. See new docs. |
you can use https://www.npmjs.com/package/babel-node-modules |
This boilerplate uses a nested
node_modules
folder to make internal references cleaner (I like it). However, when the code under the folder is ported to ES6, it is no longer compiled bybabel-node
because it is assumed to be a module.Options:
node
rather thanbabel-node
The text was updated successfully, but these errors were encountered: