Skip to content
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

Using ES6 imports #194

Open
pito-svk opened this issue Feb 6, 2016 · 2 comments
Open

Using ES6 imports #194

pito-svk opened this issue Feb 6, 2016 · 2 comments

Comments

@pito-svk
Copy link

pito-svk commented Feb 6, 2016

I got an error, when I use import instead of require.

When I use:

const cluster = require('cluster');

everything works,

Starting master, pid 5174, spawning 4 workers
Server running at http://localhost:4545
Worker 3 started
Server running at http://localhost:4545
Worker 2 started
Server running at http://localhost:4545
Worker 4 started
Server running at http://localhost:4545
Worker 1 started

but when I use

import * as cluster from 'cluster';

I got

crop

I run cluster with this code:

`if (cluster.isMaster) {
var numCpus = require('os').cpus().length;

console.log('Starting master, pid ' + process.pid + ', spawning ' + numCpus + ' workers');

for (var i = 0; i < numCpus; i++) {
    cluster.fork();
}

cluster.on('listening', function(worker) {
    console.log('Worker ' + worker.id + ' started');
});

cluster.on('death', function(worker) {
    console.log('Worker ' + worker.id + ' died, restarting...');
    cluster.fork();
});

} else {
server.listen(
port, () => console.log('Server running at http://localhost:' + port)
)
}`

@yindia
Copy link

yindia commented Mar 16, 2017

I am also facing same issue

@yindia
Copy link

yindia commented Mar 16, 2017

index.js

require('babel-core/register')({
  presets: ['node6']
});

const app = require('./test.js');
app();``

test.js

import cluster from 'cluster'
module.exports = function() {
if (cluster.isMaster) {
    for(let i = 0; i < 2; ++i) {
        cluster.fork();
    }
    cluster.on('exit', (worker) => console.log('Worker ' + worker.process.pid + ' exitted.'));
} else {

    console.log('Worker ' + cluster.worker.process.pid);
    process.exit(0);
}
}

Run : sudo babel-node --presets node6 index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants