Skip to content

Fix Location constructor import error using safe access#186

Open
rafaelmerlotto wants to merge 2 commits into
rmyndharis:mainfrom
rafaelmerlotto:fix/Location-constructor-error-import
Open

Fix Location constructor import error using safe access#186
rafaelmerlotto wants to merge 2 commits into
rmyndharis:mainfrom
rafaelmerlotto:fix/Location-constructor-error-import

Conversation

@rafaelmerlotto
Copy link
Copy Markdown

Description

Fix for Location is not a constructor error when using dynamic import of whatsapp-web.js.
Location isndometimes nested under default depending on module resolution (ESM/CJS interop), causing runtime crashes.

Issue:

Location in undefined when using dynamic import:
const { Location } = await import('whatsapp-web.js');

This causes:

TypeError: Location is not a constructor

Cause:

Depending on the module resolution, Location is available unde Default instead of the top-level export.

Fix:

Use a safe access to support both cases:

const module = await import("whatsapp-web.js");

const Location = module.Location || module.default?.Location

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • Tests added/updated
  • Documentation updated
  • Lint passes
  • Self-reviewed

Screenshots (if applicable)

N/A

Related Issues

N/A

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

Successfully merging this pull request may close these issues.

1 participant