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

Error: Cannot find module - electron-webpack #26

Open theCele opened 4 years ago

theCele commented 4 years ago

I am trying to make it work threads-plugin with electron-webpack. I have the example here https://github.com/theCele/electron-webpack-thread

By the way - it works great for JS, only when the files are typescript I don't see the bundle.worker.js in the dist/main folder.

(node:14980) UnhandledPromiseRejectionWarning: Error: Cannot find module 'D:\dev\electron-webpack-thread\dist\main\child'
  Require stack:
  - D:\dev\electron-webpack-thread\dist\main\main.js
  - D:\dev\electron-webpack-thread\node_modules\electron\dist\resources\default_app.asar\main.js
  -
      at Module._resolveFilename (internal/modules/cjs/loader.js:961:15)
      at Function.o._resolveFilename (electron/js2c/browser_init.js:257:921)
      at Function.resolve (internal/modules/cjs/helpers.js:83:19)
      at resolveScriptPath (webpack-internal:///./node_modules/threads/dist-esm/master/implementation.node.js:70:19)
      at new Worker (webpack-internal:///./node_modules/threads/dist-esm/master/implementation.node.js:84:19)
      at Object.exports.runner (webpack-internal:///./src/main/parent.ts:6:43)
      at createMainWindow (webpack-internal:///./src/main/index.ts:58:14)
      at App.eval (webpack-internal:///./src/main/index.ts:76:18)
      at App.emit (events.js:310:20)

I have followed all instructions. Not sure what I do wrong

  1. Added "target": "esnext" to tsconfig.json

  2. Added threads-plugin to webpack.main.additions.js and webpack.renderer.additions.js

  3. Added "whiteListedModules": ["threads"] to package.json

I've lost days looking around but couldn't find a solution. Also, I'm not sure if it is electron-webpack or threads-plugin issue.

Could you please have a look at my implementation? What do you think cases this TypeScript issue?

andywer commented 4 years ago

Sorry for the late reply, @theCele! Might be related to #29, not sure.

Can you try the small fix I proposed there? Another quick guess: Maybe webpack's resolve.extensions is not yet set to include *.ts/*.tsx files?