Closed astorm closed 11 months ago
I'm not 100% sure if this is related, but I think the issue is that the code handling this has not yet been moved to iitm: https://github.com/DataDog/dd-trace-js/blob/6eeb958b5638281a89f4e7d7e03d5f66aebe8547/packages/datadog-instrumentations/src/helpers/hook.js#L25-L34
The exported
object corresponds to the result of import * as exported from 'module-name'
(i.e. a namespace import), and so if a module has default exports (as fastify
does), then that can be accessed with exported.default
.
I'll close this since it's just a matter of using that .default
property. Please feel free to comment here again if this doesn't resolve it for you.
Expected Behavior
When hooking a module that exports a function, the exported object passed to the hook will also be a function.
Actual Behavior
When hooking a module that exports a function, the exported object passed to the hook is not a function.
Steps to Reproduce the Problem
We've noticed that, unlike
require-in-the-middle
, if you're trying to import a module that exports a function object by default that the function won't be callable.That is -- if we install
fastify
andimport-in-the-middle
in atype="module"
projectand have a simple sample program that looks like this
We get an error when running the program.
With a
require-in-the-middle
hook, theexported
variable is the callable function exported by the fastify module.Is this something we could get
import-in-the-middle
doing? Or are there :wave: reasons :wave: this isn't possible with either ESM modules or loader hooks?For context -- This is a small isolated example of a larger problem we're trying to solve. We have a piece of software with a large number of
require-in-the-middle
hooks. We'd like to be able to provide our users with the same functionality if they happen to be usingimport
statements while still supporting folks who are sticking with CommondJS modules at the same time. The closerimport-in-the-middle
's behavior is torequire-in-the-middle
the less we need branching code or refactoring of our existing hooks.Specifications