Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc: help needed, make use of worker-loader #606

Closed
fletcher2 opened this issue Jul 26, 2019 · 1 comment
Closed

Misc: help needed, make use of worker-loader #606

fletcher2 opened this issue Jul 26, 2019 · 1 comment

Comments

@fletcher2
Copy link

I tried to make use of worker-loader but it broke the grunt process:

Example Operation

//operations/WorkerLoaderTest.mjs
import Operation from "../Operation.mjs";
import Worker from 'worker-loader!./Worker.js';
/**
 * WorkerLoaderTest operation
 */
class WorkerLoaderTest extends Operation {
    /**
     * WorkerLoaderTest constructor
     */
    constructor() {
        super();
        this.name = "WorkerLoaderTest";
        this.module = "Default";
        this.description = "";
        this.inputType = "string";
        this.outputType = "string";
    }
    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        return input
    }
}
export default WorkerLoaderTest;

Example Worker:

//operations/Worker.js
const _ = require('lodash')
const obj = { foo: 'foo' }
_.has(obj, 'foo')
// Post data to parent thread
self.postMessage({ foo: 'foo' })
// Respond to message from parent thread
self.addEventListener('message', (event) => console.log(event))

grunt dev output

grunt dev
[[Running "clean:dev" (clean) task
>> 0 paths cleaned.

Running "clean:config" (clean) task
>> 1 path cleaned.

Running "exec:generateConfig" (exec) task

--- Regenerating config files. ---
Written operation index.
>> internal/modules/cjs/loader.js:874
>>       internalBinding('task_queue').triggerFatalException(e);
>>                                     ^
>>                                                                                                                                                                                                                                            
>> Error: Cannot find module worker-loader!./Worker.js
>>     at search (internal/modules/esm/default_resolve.js:29:12)
>>     at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:65:11)
>>     at Loader.resolve (internal/modules/esm/loader.js:58:33)
>>     at Loader.getModuleJob (internal/modules/esm/loader.js:113:40)
>>     at ModuleWrap.promises.module.link (internal/modules/esm/module_job.js:38:40)
>>     at link (internal/modules/esm/module_job.js:37:36)
--- Config scripts finished. ---


Running "concurrent:dev" (concurrent) task
    Running "watch:config" (watch) task
    Waiting...
    Running "webpack-dev-server:start" (webpack-dev-server) task
    ℹ 「wds」: Project is running at http://0.0.0.0:8080/webpack-dev-server/
    ℹ 「wds」: webpack output is served from /
    ℹ 「wds」: Content not from webpack is served from ...
Project is running at http://0.0.0.0:8080/webpack-dev-server/
    webpack output is served from /
    ✖ 「wdm」: Hash: 84fe22601068e73fa504
    Version: webpack 4.35.2
    Time: 4963ms
    Built at: 07/26/2019 1:01:17 PM
                                            Asset      Size  Chunks                    Chunk Names
    assets/570eb83859dc23dd0eec423a49e147fe.woff2  43.3 KiB          [emitted]         
                                  assets/main.css   638 KiB    main  [emitted]  [big]  main
                       images/cook_male-32x32.png  1.59 KiB          [emitted]         
                     images/cyberchef-128x128.png  5.83 KiB          [emitted]         
                          images/file-128x128.png  18.9 KiB          [emitted]         
                            images/file-32x32.png   1.9 KiB          [emitted]         
                               images/fork_me.png  5.33 KiB          [emitted]         
                                   images/map.png  1.27 MiB          [emitted]  [big]  
                                       index.html  85.2 KiB          [emitted]         
                                          main.js  5.62 MiB    main  [emitted]  [big]  main
    ℹ 「wdm」: Failed to compile.

Worker loader version:

npm info worker-loader

[email protected] | MIT | deps: 2 | versions: 25
...

The example is taken from https://github.com/webpack-contrib/worker-loader

Is there anyone with more knowledge of webpack and webworker here who could help?

@n1474335
Copy link
Member

Unfortunately you can't run a WebWorker from inside a WebWorker. All operations run inside a worker so you won't be able to achieve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants