andywer / threads-plugin

📦 Makes your threads.js code build with webpack out of the box.
Apache License 2.0
28 stars 6 forks source link

TypeScript emitted no output #22

Open raz-sinay opened 4 years ago

raz-sinay commented 4 years ago

Hi, I've encountered something strange when using the plugin when writing typescript workers. inside an electron environment and using electron-webpack and electron-builder for bundling and building.

When I run the app in dev mode (yarn dev), everything get's transpiled, bundled and running OK, but whenever trying to build the app into an executable, I get errors from typescript, failing the build.

ERROR in ./src/main/workers/myWorker.ts (./node_modules/ts-loader??ref--8-0!./node_modules/eslint-loader??ref--6!./src/main/workers/myWorker.ts) Module build failed (from ./node_modules/ts-loader/index.js): Error: TypeScript emitted no output for C:\Dev\Repositories\my-repo\src\main\workers\myWorker.ts. at makeSourceMapAndFinish (C:\Dev\Repositories\my-repo\node_modules\ts-loader\dist\index.js:80:15) at successLoader (C:\Dev\Repositories\my-repo\node_modules\ts-loader\dist\index.js:68:9) at Object.loader (C:\Dev\Repositories\my-repo\node_modules\ts-loader\dist\index.js:22:12)

Last time it happened to me, the problem was really petty. When I defined my array as const myArray: MyType[] = [];, typescript failed to build. Eventually, only after changing the code to be: const myArray: Array<MyType> = new Array(); it worked.

now I'm facing some another similar issue , that prevents me to do some kind of easy reduce code over an array.

my webpack is based upon electron-webpack's defaults, and I added this to allow node's built-in api inside workers:

const NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
const ThreadsPlugin = require('threads-plugin');
module.exports = function (config) {
  config.plugins.unshift(
    new ThreadsPlugin({
      plugins: [new NodeTargetPlugin()],
      target: 'electron-node-worker'
    })
  );
  return config;
};

I have tried both with and without ts-node installed, the result is the same.

There are actually 2 errors listed, the one I've mentioned above. and this one:

ERROR in ./src/main/workers/myWorker.ts (./node_modules/threads-plugin/dist/loader.js?{"name":"3"}!./src/main/workers/myWorker.ts) Module build failed (from ./node_modules/threads-plugin/dist/loader.js): ModuleBuildError: Module build failed (from ./node_modules/ts-loader/index.js): Error: TypeScript emitted no output for C:\Dev\Repositories\my-repo\src\main\workers\myWorker.ts. at makeSourceMapAndFinish (C:\Dev\Repositories\my-repo\node_modules\ts-loader\dist\index.js:80:15) at successLoader (C:\Dev\Repositories\my-repo\node_modules\ts-loader\dist\index.js:68:9) at Object.loader (C:\Dev\Repositories\my-repo\node_modules\ts-loader\dist\index.js:22:12) at C:\Dev\Repositories\my-repo\node_modules\webpack\lib\NormalModule.js:316:20 at C:\Dev\Repositories\my-repo\node_modules\loader-runner\lib\LoaderRunner.js:367:11 at C:\Dev\Repositories\my-repo\node_modules\loader-runner\lib\LoaderRunner.js:233:18 at runSyncOrAsync (C:\Dev\Repositories\my-repo\node_modules\loader-runner\lib\LoaderRunner.js:143:3) at iterateNormalLoaders (C:\Dev\Repositories\my-repo\node_modules\loader-runner\lib\LoaderRunner.js:232:2) at iterateNormalLoaders (C:\Dev\Repositories\my-repo\node_modules\loader-runner\lib\LoaderRunner.js:221:10) at C:\Dev\Repositories\my-repo\node_modules\loader-runner\lib\LoaderRunner.js:236:3 at Object.context.callback (C:\Dev\Repositories\my-repo\node_modules\loader-runner\lib\LoaderRunner.js:111:13) at Object.module.exports (C:\Dev\Repositories\my-repo\node_modules\eslint-loader\index.js:274:11) @ ./src/main/ipc/workerDispatchers/myWorker.ts 1:0-158 @ ./src/main/ipc/index.ts @ ./src/main/index.ts @ multi ./src/main/index.ts

I can't tell the actual typescript error, even if there is one, because it's not showing at the output. I'm afraid something in my configurations isn't defined properly. would love to get your advice. What am I missing?

andywer commented 4 years ago

Hey @raz-sinay! Sorry, but I don't have a good solution either…

You could try removing the new NodeTargetPlugin(), as the threads-plugin should apply the NodeTargetPlugin automatically to the webpack child compiler that creates the worker bundle.

But yeah, I guess probably something's wrong with the loader configuration. Without seeing the actual TypeScript error it will be tough, though.

hrishabhkumar commented 4 years ago

Is It fixed or we have to use only js for now?

andywer commented 4 years ago

I am not sure what the current status is, but we have always used threads.js with the threads-plugin with TypeScript and never saw that error. Might be specific to Electron, might be specific to that particular webpack config here, hard to tell without further details @raz-sinay

In general, you should expect the plugin to work with TypeScript 😉