Skip to content

"ImportInTheMiddle" will crash at run-time #4691

Closed
@jd-carroll

Description

@jd-carroll

What happened?

Warning output from esbuild bundler.

▲ [WARNING] Constructing "ImportInTheMiddle" will crash at run-time because it's an import namespace object, not a constructor [call-import-namespace]
    node_modules/@opentelemetry/instrumentation-mongoose/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:259:30:
      259 │ ...     var esmHook = new ImportInTheMiddle([module_2.name], { in...
          ╵                           ~~~~~~~~~~~~~~~~~
  Consider changing "ImportInTheMiddle" to a default import instead:
    node_modules/@opentelemetry/instrumentation-mongoose/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:48:7:
      48 │ import * as ImportInTheMiddle from 'import-in-the-middle';
         │        ~~~~~~~~~~~~~~~~~~~~~~
         ╵        ImportInTheMiddle
6 of 16 warnings shown (disable the message limit with --log-limit=0)
  ...310dc1affb2720b6af2dd368949f880c1da144faa5a6860bc328c2/index.mjs  3.8mb ⚠️
⚡ Done in 144ms

From the code, I would have to agree with the warning that this will crash if used.

I don't understand how you could import like this:
It is not valid to import like this:

And then instantiate like this:

const esmHook =
new (ImportInTheMiddle as unknown as typeof ImportInTheMiddle.default)(
[module.name],
{ internals: false },
<HookFn>hookFn
);

It will absolutely throw an exception.

For ESM, the instantiation would need to look like:

var esmHook = new ImportInTheMiddle.default.default( ... );

But there are lots of things I do not know, so would be interested to hear if this would actually work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:p1Bugs which cause problems in end-user applications such as crashes, data inconsistencies, etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions