2016-09-16 12 views
0

私は正式に諦めます。 es6インポート構文を使用するノードes6プロジェクトを実行しようとしていますが、子プロセスは機能しません。問題は、childprocess.forkがbabel-nodeではなくnodeを使用することです。私はbabel-nodeを使って実行するようにしましたが、現在はprocess.sendを介して通信することはできません。私は問題を解決するためのオプションを探しています。おそらくもっと簡単な方法があります。私はこれを与えノードの子プロセスでES6のインポート構文を実行

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)); 

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

答えて

2

Babel CLI pageは言う:

You should not be using babel-node in production.

代わりに、最初にすべてのファイルをコンパイルして、コンパイルされたファイルにchildProcess.fork()を実行します。

+0

子プロセスフォークがファイルパスを実行する必要があります。すべてのファイルをビルドファイルにコンパイルすると、そのコードをどのようにフォークしますか? – wayofthefuture

+0

@wayofthefuture Babelはすべてのファイルを1つのビルドファイルにコンパイルしません。各ファイルは別々にコンパイルされます。 –

+0

これは、プロジェクト全体が別の拡張子のファイルで汚染されることを意味しますか? – wayofthefuture

0

誰かが同じ問題を抱えている場合。しかし、モカを使用するなどのテスト環境。 this issue私はモカに問題を解決できました。

Running babel-node node_modules/mocha/bin/_mocha test.js applies by default the compiler to the child process and there is no need to set the execPath .

PS: Once you run the mocha with babel-node there is no need to pass --require or --compilers .

関連する問題