Skip to content

babel-cli and babel-node ignore global presets (installed with npm -g) #2816

@moretti

Description

@moretti

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)
(...)

Activity

loganfsmyth

loganfsmyth commented on Nov 4, 2015

@loganfsmyth
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

RobertCZ commented on Nov 4, 2015

@RobertCZ

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

moretti commented on Nov 4, 2015

@moretti
Author

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

GGAlanSmithee commented on Nov 4, 2015

@GGAlanSmithee

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

moretti commented on Nov 4, 2015

@moretti
Author

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

sebmck commented on Nov 4, 2015

@sebmck
Contributor

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.

Bargs

Bargs commented on Nov 10, 2015

@Bargs

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

jamiebuilds commented on Nov 11, 2015

@jamiebuilds
Contributor

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

bradfloodx

bradfloodx commented on Aug 9, 2017

@bradfloodx

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

RoboBurned commented on Oct 3, 2017

@RoboBurned

@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.

added
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue
on May 4, 2018
locked as resolved and limited conversation to collaborators on May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @loganfsmyth@sebmck@jamiebuilds@RobertCZ@bradfloodx

        Issue actions

          babel-cli and babel-node ignore global presets (installed with npm -g) Β· Issue #2816 Β· babel/babel