threads-plugin icon indicating copy to clipboard operation
threads-plugin copied to clipboard

Cannot import built-in node modules in worker in electron/webpack build

Open jc-lab opened this issue 4 years ago • 16 comments

https://github.com/jc-lab/threads-plugin-problem See the repository above.

Error when using module as esnext in tsconfig. If you use commonjs instead of esnext, threads-plugin will not detect Worker.

> npm run build
...
Child WorkerPluginLoader:
     2 assets
    Entrypoint 0 = 0.bundle.worker.js 0.bundle.worker.js.map
     [6] (webpack)/buildin/harmony-module.js 573 bytes {0} [built]
    [15] ./node_modules/ts-loader??ref--4!./src/test.thread.ts + 2 modules 16.7 KiB {0} [built]
         | ./node_modules/ts-loader??ref--4!./src/test.thread.ts 730 bytes [built]
         |     + 2 hidden modules
        + 26 hidden modules

    ERROR in ./src/test.thread.ts (./node_modules/ts-loader??ref--4!./src/test.thread.ts)
    Module not found: Error: Can't resolve 'fs' in 'D:\temp\webpack-worker-test\src'
     @ ./src/test.thread.ts (./node_modules/ts-loader??ref--4!./src/test.thread.ts) 3:0-25 8:22-42

    ERROR in ./src/test.thread.ts (./node_modules/ts-loader??ref--4!./src/test.thread.ts)
    Module not found: Error: Can't resolve 'zlib' in 'D:\temp\webpack-worker-test\src'
     @ ./src/test.thread.ts (./node_modules/ts-loader??ref--4!./src/test.thread.ts) 4:0-29 9:23-41

jc-lab avatar Jan 06 '20 12:01 jc-lab