Skip to content

Using ES6 imports #194

Description

@pito-svk

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)
)
}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions