andywer / andywer/threads.js

"Error: Cannot find module '/engine-learn/Worker'" or "Error: expose() called in the master thread."

未關閉
#465 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
TypeScript
星號
3.5k
分支
173
PR 合併指標
30 天內沒有已合併 PR

描述

My Nx setup using `threads.js` ain't working...I'm getting either this error:
> Error: Cannot find module 'engine-learn/Worker'

...when my setup looks like this:
```
// index.ts
export * from './EngineLearn';

// Worker.ts
import { expose } from 'threads/worker';

const trainModel = async () => {
console.log("In trainModel");
};

expose(trainModel);

// EngineLearn.ts
import { Pool, spawn, Worker } from 'threads';

export class EngineLearn {
trainModels = async () => {
console.log('Hello');
const pool = Pool(() => spawn(new Worker('./Worker')));
};
}
```
...or, if I export `Worker.ts` in my root `index.ts`, like this:
```
// index.ts
export * from './EngineLearn';
export * from './Worker';
```
...I get:
> "Error: expose() called in the master thread."

It seems the module is not included in the build if I export it in `index.ts`, and so cannot be found; but, if I do, `expose()` is immediately invokes and it gives rise to the other error.

What to do 🤷🏻

I am using the `@nrwl/esbuild:esbuild` build executor.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。