gyss
gyss

Reputation: 1843

Using babel with node cluster

I have a very simple program developed with ES6 and transpiled with Babel.

import kue from 'kue';
import cluster from 'cluster';
const queue = kue.createQueue();

const clusterWorkerSize = require('os').cpus().length;

if (cluster.isMaster) {
  kue.app.listen(3000);
  for (var i = 0; i < clusterWorkerSize; i++) {
    cluster.fork();
  }
} else {
  queue.process('email', 10, function(job, done){
    ...
  });
}

The problem comes when I run the program with

$ babel-node --presets es2015 program.js

The master process run without problem but the children crash with:

import kue from 'kue';

SyntaxError: Unexpected reserved word

Any idea of how run the children with Babel?

NOTE: one option is to generate a dist/ folder with all the code transpiled to ES5, but I leave that for the last.

Upvotes: 2

Views: 925

Answers (1)

just-boris
just-boris

Reputation: 9766

The problem here is that child processes are run under the node, not babel-node.

Try to use babel require hook instead of CLI.

Upvotes: -1

Related Questions