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

TypeError: Cannot convert undefined or null to object #186

Open
DarrenMa opened this issue Oct 26, 2023 · 2 comments
Open

TypeError: Cannot convert undefined or null to object #186

DarrenMa opened this issue Oct 26, 2023 · 2 comments

Comments

@DarrenMa
Copy link

Hi suhas,

Is it possible to refactor some of the query building logic into modules? I want to separate parts of the process into nodejs modules. but when I do this I get the title error.

I posted the full question here

Perhaps it's not possible?

Like this:

import esb from 'elastic-builder';
import { ToElasticFilter } from 'filtermodule';
import { ToElasticSort } from 'sortmodule';

const run = () => {

  // add any customers filters here
  const boolBody = ToElasticFilter(); // esb.boolQuery().must(esb.regexpQuery('catch_all', `.*test.*`).flags('NONE'));

  // apply the sorting here
  const s = ToElasticSort(); // esb.sort('catch_all', 'asc').missing('_last').mode('max').unmappedType('keyword');

  // build the base query here
  const body = esb.requestBodySearch().query(boolBody).sort(s);

  console.log(JSON.stringify(body.toJSON(), null, 2));

};

run();

Thank you for your time and work.

@sudo-suhas
Copy link
Owner

Could you share the stack trace? It is not clear which step is failing. It is possible that there is an issue with the import since you are not using relative paths

@DarrenMa
Copy link
Author

DarrenMa commented Oct 26, 2023

Stacktrace:

C:\Program Files\nodejs\node.exe .\dist\index.js
Uncaught TypeError TypeError: Cannot convert undefined or null to object
    at formatProperty (c:\Users\d.ma\Projects\github\esb_modules_sample\service\node_modules\elastic-builder\src\core\inspect.js:289:10)
    at <anonymous> (c:\Users\d.ma\Projects\github\esb_modules_sample\service\node_modules\elastic-builder\src\core\inspect.js:169:13)
    at formatValue (c:\Users\d.ma\Projects\github\esb_modules_sample\service\node_modules\elastic-builder\src\core\inspect.js:168:23)
    at inspect (c:\Users\d.ma\Projects\github\esb_modules_sample\service\node_modules\elastic-builder\src\core\inspect.js:39:12)
    at checkType (c:\Users\d.ma\Projects\github\esb_modules_sample\service\node_modules\elastic-builder\src\core\util.js:28:20)
    at query (c:\Users\d.ma\Projects\github\esb_modules_sample\service\node_modules\elastic-builder\src\core\request-body-search.js:84:9)
    at run (c:\Users\d.ma\Projects\github\esb_modules_sample\service\src\index.ts:14:40)
    at <anonymous> (c:\Users\d.ma\Projects\github\esb_modules_sample\service\src\index.ts:20:1)
    at Module._compile (internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (internal/modules/cjs/loader:1310:10)
    at Module.load (internal/modules/cjs/loader:1119:32)
    at Module._load (internal/modules/cjs/loader:960:12)
    at executeUserEntryPoint (internal/modules/run_main:86:12)
    at <anonymous> (internal/main/run_main_module:23:47)
Process exited with code 1

It seems that, because the esb instance is different within the module, compared to the instance used within the service, then this error occurs.

Test project here

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