Skip to content
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-cli and babel-node ignore global presets (installed with npm -g) #2816

Closed
moretti opened this issue Nov 4, 2015 · 10 comments
Closed
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@moretti
Copy link

moretti commented Nov 4, 2015

Here are the steps to reproduce the problem:

$ babel --version
6.1.1 (babel-core 6.0.20)

$ npm ls -g --depth=0 | grep babel-preset
├── babel-preset-es2015@6.0.15

$ babel --presets es2015 index.js
Error: Couldn't find preset "es2015"
    at OptionManager.mergePresets (/Users/user/.node/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:310:17)
(...)

$ babel-node --version
6.1.1

$ babel-node --presets es2015 -e "const foo = 'bar'"
Error: Couldn't find preset "es2015"
    at OptionManager.mergePresets (/Users/user/.node/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:310:17)
(...)
@loganfsmyth
Copy link
Member

Installing Babel globally should be avoided. If you need Babel in a project, you should install it into the project itself and run it as an npm script or via

$(npm bin)/babel-node

or

./node_modules/.bin/babel-node

@RobertCZ
Copy link

RobertCZ commented Nov 4, 2015

from the docs (https://babeljs.io/docs/usage/cli/):

Using npm you can install Babel globally, making it available from the command line.

so: globally or not?

@moretti
Copy link
Author

moretti commented Nov 4, 2015

I agree that in general it should be avoided and I personally install babel as dev dependency in my projects, but I like using the CLI for quick tests.

For example, how am I supposed to try all these new cool presets? 😄

@GGAlanSmithee
Copy link

Why wouldn't you be able to use the CLI just because you installed it with --save or --save-dev? It's still installed, just not globally accessable. It's in the node_modules/.bin folder.. Or am I missunderstanding something?

@moretti
Copy link
Author

moretti commented Nov 4, 2015

I am well aware of the workarounds you listed, I reported the issue because it's inconsistent with the documentation and I'm not completely sure if this should be considered a bug or not.

@sebmck
Copy link
Contributor

sebmck commented Nov 4, 2015

We resolve plugins and presets relative to the input file path. You're using the CLI and haven't referenced a file on disk so there's nowhere for it to be resolved from. Put it in a file and execute it and it will work.

@sebmck sebmck closed this as completed Nov 4, 2015
@Bargs
Copy link

Bargs commented Nov 10, 2015

I'd love to be able to fire up a REPL for some quick tests written in ES6. Sometimes you just want to test something out and there's no project context to do it in. Couldn't babel-node resolve the path for presets based on the current working directory with a fallback to global node-modules if no input file was specified? Maybe I'm totally missing something, but it seems pointless to have a babel based REPL if you can't load any presets or plugins.

@jamiebuilds
Copy link
Contributor

The REPL was already came with a lot of caveats, I'm tempted to say remove it.

@brad-sf
Copy link

brad-sf commented Aug 9, 2017

I'm also using babel-cli and babel-node for running quick tests locally without having a whole project set up. You can easily install the preset in the folder you are testing:

npm install babel-preset-es2015

And then run your test

babel-node --presets es2015 index.js

Obviously it would be ideal if babel-node checked the global folder after checking the current working directory, but this is a workaround that is fairly easy to do.

@RoboBurned
Copy link

@kittens As I can see this is not exactly how it works now.
I have the following file structure.
server
server.js
import App from '..\client\components\App'
client
components
App.jsx

When I run babel-node in server directory and pass it server.js as a input file it raises an error because it can't find react preset relative to directory \client\components. I have react preset installed in server/node_modules but not in client/node_modules.
So if I understood correct it looks for presets for each file it process.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

9 participants