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

cli pipe not working #6758

Closed
BebeSparkelSparkel opened this Issue Nov 7, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@BebeSparkelSparkel

BebeSparkelSparkel commented Nov 7, 2017

When piping into babel the script is not compiled.

When using the cli it works as expected when not piping in the file.

Expected Behavior

Working when referencing a file:

$ npx babel ./try_babel.js
'use strict';

var a = 'hi';

I would expect all commands

$ npx babel ./try_babel.js
$ cat try_babel.js | npx babel
$ npx babel < ./try_babel.js 

to do the same thing

Current Behavior

Does not work when piped in:

$ cat try_babel.js | npx babel
const a = 'hi';

$ # nor with "<" like docs from https://babeljs.io/docs/usage/cli/#babel-piping-files
$ npx babel < ./try_babel.js 
const a = 'hi';

Test File

File to compile (try_babel.js)

const a = 'hi'

Context

Trying to pipe output of browserify into babel for some quick tests.

Your Environment

software version(s)
Babel 6.26.0 (babel-core 6.26.0)
node v8.5.0
npm 5.5.1
Operating System Mac 10.11.6
@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Nov 7, 2017

Collaborator

Hey @BebeSparkelSparkel! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Collaborator

babel-bot commented Nov 7, 2017

Hey @BebeSparkelSparkel! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@victordidenko

This comment has been minimized.

Show comment
Hide comment
@victordidenko

victordidenko Jan 13, 2018

I've faced similar issue with @babel/cli version 7.0.0-beta.37:
When I piping file into babel, it ignores .babelrc.
But if I add parameter -f <anyname.js> everything is working fine:

-f, --filename [filename] filename to use when reading from stdin - this will be used in source-maps, errors etc

Try it

$ npx babel ./try_babel.js
$ cat try_babel.js | npx babel -f try_babel.js
$ npx babel -f try_babel.js < ./try_babel.js
$ echo 'const a = "hi"' | npx babel -f 1.js

victordidenko commented Jan 13, 2018

I've faced similar issue with @babel/cli version 7.0.0-beta.37:
When I piping file into babel, it ignores .babelrc.
But if I add parameter -f <anyname.js> everything is working fine:

-f, --filename [filename] filename to use when reading from stdin - this will be used in source-maps, errors etc

Try it

$ npx babel ./try_babel.js
$ cat try_babel.js | npx babel -f try_babel.js
$ npx babel -f try_babel.js < ./try_babel.js
$ echo 'const a = "hi"' | npx babel -f 1.js
@BebeSparkelSparkel

This comment has been minimized.

Show comment
Hide comment
@BebeSparkelSparkel

BebeSparkelSparkel Jan 13, 2018

Thanks for the work around. Would not have expected that

BebeSparkelSparkel commented Jan 13, 2018

Thanks for the work around. Would not have expected that

@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Jan 13, 2018

Member

This is by design: if Babel doesn't know where the file comes from, it can't choose the correct .babelrc file.
So cat try_babel.js | npx babel will run Babel with an empty configuration, without any plugin.

You can make it work in three ways:

  1. By providing the input file name, as suggested by @victordidenko
  2. By specifying which .babelrc should be used:
    cat try_babel.js | npx babel --config-file ./config/.babelrc
    
  3. By setting the --plugins and --presets options:
    cat try_babel.js | npx babel --presets babel-preset-env
    

I have opened babel/website#1512 to update the documentation.

Member

nicolo-ribaudo commented Jan 13, 2018

This is by design: if Babel doesn't know where the file comes from, it can't choose the correct .babelrc file.
So cat try_babel.js | npx babel will run Babel with an empty configuration, without any plugin.

You can make it work in three ways:

  1. By providing the input file name, as suggested by @victordidenko
  2. By specifying which .babelrc should be used:
    cat try_babel.js | npx babel --config-file ./config/.babelrc
    
  3. By setting the --plugins and --presets options:
    cat try_babel.js | npx babel --presets babel-preset-env
    

I have opened babel/website#1512 to update the documentation.

@BebeSparkelSparkel

This comment has been minimized.

Show comment
Hide comment
@BebeSparkelSparkel

BebeSparkelSparkel Jan 13, 2018

It would be nice if an error could be thrown when the .babelrc file cannot be found.

BebeSparkelSparkel commented Jan 13, 2018

It would be nice if an error could be thrown when the .babelrc file cannot be found.

@lock lock bot added the outdated label May 3, 2018

@lock lock bot locked as resolved and limited conversation to collaborators May 3, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.