Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Fixed issue with CJS being imported as ESM #2168

Merged
merged 8 commits into from
Apr 26, 2024

Conversation

jsumners-nr
Copy link
Contributor

This PR resolves #2155. This PR supercedes #2158.

@jsumners-nr jsumners-nr marked this pull request as ready for review April 26, 2024 16:52
@jsumners-nr jsumners-nr requested a review from bizob2828 April 26, 2024 17:03
Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall makes sense and looks good. a few comments

* SPDX-License-Identifier: Apache-2.0
*/

'use strict'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd put this in lib/util

t.context.agent = agent

const { default: foo } = await import('./foo.cjs?v=' + crypto.randomBytes(16).toString('hex'))
t.context.mod = foo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you just import this and then access all 3 different exports and verify it works as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I understand the question. I have to import it after the "agent" is setup because otherwise the registerHooks will not pick up the module.

helper.instrumentMockedAgent = (conf, setState = true, shimmer = require('../../lib/shimmer')) => {
shimmer.debug = true
const agent = helper.loadMockedAgent(conf, setState)
shimmer.bootstrapInstrumentation(agent)
shimmer.registerHooks(agent)
helper.maybeLoadSecurityAgent(agent)
return agent
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh so i meant importing the file to get at default, foo and just the raw module.exports. Looking at this right now you're just getting default correct?

@jsumners-nr jsumners-nr requested a review from bizob2828 April 26, 2024 18:57
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Newrelic + Fastify: Function.prototype.apply was called on #<Object>, which is an object and not a function
2 participants