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

Does not handle CallExpression in ExportDefaultDeclaration node #77

Closed
mohd-akram opened this issue May 19, 2024 · 4 comments · Fixed by #85 or getsentry/sentry-javascript#12388
Closed

Comments

@mohd-akram
Copy link
Contributor

mohd-akram commented May 19, 2024

Expected Behavior

Works.

Actual Behavior

TypeError: Cannot read properties of undefined (reading 'name')
    at getEsmExports (/Users/user/code/project/node_modules/import-in-the-middle/lib/get-esm-exports.js:71:59)
    at getExports (/Users/user/code/project/node_modules/import-in-the-middle/lib/get-exports.js:80:12)
    at async processModule (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:134:23)
    at async processModule (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:160:20)
    at async processModule (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:160:20)
    at async processModule (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:160:20)
    at async processModule (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:160:20)
    at async processModule (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:160:20)
    at async getSource (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:269:60)
    at async load (/Users/user/code/project/node_modules/import-in-the-middle/hook.js:335:26)

Steps to Reproduce the Problem

I'm getting this after updating Sentry to 8.x. I'm not sure where exactly import-in-the-middle is being called from, but the gist of it is that it is crashing on this file (node_modules/adminjs/lib/frontend/components/app/sort-link.js) because it has a function call in the export.

  1. require('import-in-the-middle/lib/get-esm-exports')({moduleSource: 'export default parseInt("1");', defaultAs: 'SortLink'})

Specifications

  • Version: 1.7.4
  • Platform: macOS
  • Subsystem: ?
@timfish
Copy link
Contributor

timfish commented May 27, 2024

I haven't seen one before!

Can you try applying this patch which combines a load of outstanding PRs and see if that fixes it?

@mohd-akram
Copy link
Contributor Author

Tried it, it doesn't work. It only patches hook.js while the problem is in get-esm-exports.js.

@timfish
Copy link
Contributor

timfish commented May 29, 2024

I've tried reproducing this with a simple export default parseInt("1") but it parses without error. Do you have a more full example to reproduce this?

@mohd-akram
Copy link
Contributor Author

The issue only happens when defaultAs is provided, as in the one-liner I mentioned. I imagine it comes from here in the library where this happens. The code expects a function node but doesn't check the type: https://github.com/DataDog/import-in-the-middle/blob/bf3a4fbb0b0a4fd806aefb8d2a598894303a0ebf/lib/get-esm-exports.js#L67-L70

@bengl bengl closed this as completed in #85 May 31, 2024
@bengl bengl closed this as completed in 74124e9 May 31, 2024
AbhiPrasad added a commit to getsentry/sentry-javascript that referenced this issue Jun 6, 2024
resolves #12242
(although there are still some follow ups)

https://github.com/open-telemetry/opentelemetry-js/releases/tag/v1.25.0

I think this lockfile looks correct, but lmk if this feels off.

resolves #12011
resolves #12059
resolves #12154
resolves #12237
resolves nodejs/import-in-the-middle#77 cc
@mohd-akram
billyvg pushed a commit to getsentry/sentry-javascript that referenced this issue Jun 10, 2024
resolves #12242
(although there are still some follow ups)

https://github.com/open-telemetry/opentelemetry-js/releases/tag/v1.25.0

I think this lockfile looks correct, but lmk if this feels off.

resolves #12011
resolves #12059
resolves #12154
resolves #12237
resolves nodejs/import-in-the-middle#77 cc
@mohd-akram
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment