10

So I follow the installation here, but babel takes very long time to compile, even small files:

app.js

let app = 1;

.babelrc

{ "presets": ["es2015"] }

package.json

"scripts": {
    "build": "babel app.js -o dist/app.js"
},
"devDependencies": {
    "babel-cli": "^6.4.5",
    "babel-preset-es2015": "^6.3.13"
}

Then npm run build will take ~30s to compile.

I'm using npm@3.3.12

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
hjrshng
  • 1,675
  • 3
  • 17
  • 30
  • Can't reproduce. What happens when you run the command directly without NPM? `node_modules/.bin/babel app.js -o dist/app.js` – Alexander O'Mara Feb 06 '16 at 19:03
  • 1
    If you're on npm 3 you should be good. Maybe clear your node_modules and reinstall to be sure? Or look in node_modules and make sure your dependencies are all flattened properly. – loganfsmyth Feb 06 '16 at 21:57
  • Yes that came from my install, ``rm -rf node_modules``, ``npm cache clean``and ``npm install``did the trick. – hjrshng Feb 07 '16 at 01:28

2 Answers2

3

You might be compiling node_modules and bower_components too.

You can try adding the ignore property in your projects .babelrc like so:

{
  ...
  "ignore": /(node_modules|bower_components)/
  ...
}

Hope this solves your issue

Aakash
  • 21,375
  • 7
  • 100
  • 81
Vineet 'DEVIN' Dev
  • 1,183
  • 1
  • 10
  • 35
1

Update September 2019

Found upgrading to Babel 7 solved this. Perhaps try:

$ npm install --save-dev @babel/core @babel/node @babel/preset-env

Your package.json should contain something like:

 "devDependencies": {
    "@babel/core": "^7.6.0",
    "@babel/node": "^7.6.1",
    "@babel/preset-env": "^7.6.0"
  }

My .babelrc file is as follows:

{
  "presets": ["@babel/preset-env"]
}

Now, when I run:

npx babel-node src/index.js

the performance is almost instantaneous (it was taking 20+ seconds with babel 6).

See the babel 7.5 docs for more details on this.

Also, for reference on the upgrade, see this stackoverflow question & answer.

arcseldon
  • 35,523
  • 17
  • 121
  • 125