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

ReferenceError: immutable_1 is not defined when using 'immutable' library #62

Open
mlsad3 opened this issue Apr 3, 2020 · 3 comments
Open

Comments

@mlsad3
Copy link

mlsad3 commented Apr 3, 2020

Hi,

This library looks really cool. Unfortunately I hit a snag when I try to use 'immutable'. For example:

  await start();

  const res1 = await job(() => {
    let i = 0;
    for (i = 0; i < 1000000; i++) {}
    let config = OrderedMap(fromJS({}));
    return i;
  });

In the above example, it fails immediately with "immutable_1 is not defined". Is this a known limitation due to the way Immutable was written (using factories)?
Thanks!

@mlsad3
Copy link
Author

mlsad3 commented Apr 3, 2020

Hmm, it seems to happen whenever I do anything inside the job (like create a new instance):

  const res1 = await job(() => {
    const configValidationManager = new ConfigValidationManager();
    let i = 0;
    for (i = 0; i < 1000000; i++) {}
    return i;
  });

This gives: Error: ConfigValidation_manager_1 is not defined
Using Node 12.16.1, microjob 0.7.0

@mlsad3
Copy link
Author

mlsad3 commented Apr 3, 2020

Looking at the .js file that TypeScript generates, I see the following:

const immutable_1 = require("immutable");
const ConfigValidation_manager_1 = __importDefault(require("./ConfigValidation.manager"));
const microjob_1 = require("microjob");
const errors_1 = require("../controllers/errors");

So it looks like the 'import' commands I have in my file won't work as they are not in the same scope as the worker...and my worker calls dozens of functions which also use various libraries, so they would all have similar issues.

@mlsad3
Copy link
Author

mlsad3 commented Apr 3, 2020

I moved all of the processing code to another file, with a couple exports:

File: My.worker.ts

export { processRawConfigWorker };

Then in Main.ts:

try {
  // Start worker pool
  await start();

  // This function will be executed in another thread
  const res = await job(
    data => {
      const { processRawConfigWorker } = require('My.worker');
      return processRawConfigWorker(data.rawConfig);
    },
    { data: { rawConfig: rawConfig } }
  );
  return res;
} catch (err) {
  console.error(err);
}

But this creates the error: "Cannot find module 'My.worker'".

Does anyone have an example using TypeScript and calling a function in another file? I tried prefixing with __dirName, but that just added '.' to the name.

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

1 participant