Run ES6 import syntax in Node child process

wayofthefuture

I officially give up. I'm trying to run a node es6 project that uses es6 import syntax, but the child processes won't work. The problem is that childprocess.fork uses node and not babel-node. I've gotten it to run using babel-node, but now they can't communicate via process.send. I'm looking for any options to solve the problem, maybe there is an easier one.

let appPath = path.dirname(require.main.filename);
let babelPath = path.join(appPath, 'node_modules/.bin/babel-node.cmd'); //WINDOWS

let filepath = path.join(__dirname, 'processes', moduleName);
let process = childProcess.fork(filepath, { execPath: babelPath });

process.on('message', msg => console.log(msg));

which gives me this:

Error: channel closed at ChildProcess.target.send (internal/child_process.js:523:16)

Michał Perłakowski

Babel CLI page says:

You should not be using babel-node in production.

Instead, compile all the files first, and then run childProcess.fork() on the compiled files.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to setup node environment to run ES6 codes involving syntax like `import ... from ...`?

how to use node module with es6 import syntax in typescript

"Import" ES6 for Node

How to import firebase-functions and firebase-admin in ES6 syntax for transpiling with Babel for Node 10

node.js run function in child process?

Is there a way to run a node task in a child process?

Correct syntax to import constants in ES6

Run node as background process from script running as child process

node.js child process change a directory and run the process

Run multiple commands from same node.js child process

Does Node Child Process Spawn Run on Multi Core CPU?

How to run and handle errors in child process spawn in node

Dynamically import JavaScript module using ES6 syntax?

In the `import` syntax of ES6, how is a module evaluated exactly?

How to import class using ES6 syntax? (without Babel)

ES6 import syntax with Angular 1.5 UI Router

How to import jquery using ES6 syntax?

linq javascript library with typescript es6 import syntax

Relation between import and destructing es6 syntax?

Import commonJS, AMD, and ES6 modules at runtime with synchronous syntax

Converting jsx with ES6 import syntax using reactify

How to import .html fragment using es6 syntax in TypeScript

How will browsers handle ES6 import/export syntax

How to import pg-promise using ES6 syntax?

Run JSX Preprocessor and use ES6 Syntax

What is a node child process?

ES6 import and export are not supported in Node.js

ES6 import statements not working in Node v8.4.0

ES6 variable import name in node.js?