Friday, 26 May 2017

Babel seems to ignore NODE_ENV

According to the docs Babel will use NODE_ENV to set env specific options if BABEL_ENV is not specified. I noticed today that this doesn't work, or at least on my machine.

package.json

{
  "name": "babel-exp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start1": "NODE_ENV=foo babel-node src/index",
    "start2": "BABEL_ENV=foo babel-node src/index"
  },
  "dependencies": {
    "babel-cli": "^6.24.1",
    "babel-preset-env": "^1.5.1"
  }
}

.babelrc

{
  "env": {
    "foo": {
      "presets": ["env"]
    }
  }
}

src/index.js

import { hello, bye } from './sayings'

console.log('hello = ', hello);

src/sayings.js

export const hello = 'hello'
export const bye = 'bye'

Running start1 with either npm or yarn results in: SyntaxError: Unexpected token import start2 logs hello =  hello correctly

node: v7.10.0 yarn: v0.24.6 npm: 4.1.1

I suppose the folks at Babel didn't change this behaviour, so it's probably something I am doing wrong. I would be happy if someone can verify this problem, or provide any other feedback.



via devboell

No comments:

Post a Comment