Secreto31126 / whatsapp-api-js

A TypeScript server agnostic Whatsapp's Official API framework
MIT License
137 stars 31 forks source link

Text is not a constructor #244

Closed HysMX closed 10 months ago

HysMX commented 11 months ago

Describe the bug Can't create a text object to send a message, it returns Text is not a constructor

To Reproduce

import { Text, Image, Document } from "whatsapp-api-js/messages";

const msg = new Text(`Copia este mensaje y envíalo al proveedor para que pueda identificarte:
Este es el resumen de tu solicitud:
*Producto solicitdado:* ${quote_accept.product}
*Presupuesto:* ${quote_accept.budget}
*Categoría:* ${quote_accept.category}

*Proveedor:* ${business.name}
*Precio Propuesto:* ${offer_accept.proposal_price}
*Mensaje del proveedor:* ${offer_accept.proposal_message}`)
await Whatsapp.sendMessage(PHONE_ID as string, customer_accept.phone, msg)

creating the text inside the sendMessage function doesn't work either, it was like that

  1. Simple and straight to the point failing snippet
  2. See error Captura de pantalla 2023-10-01 a la(s) 7 32 33 p m

Expected behavior create the Text Object to be able to send the message

Version: 2.1.2

Even const txt = new Text('Hola', false); doesn' work

Captura de pantalla 2023-10-01 a la(s) 7 38 04 p m
HysMX commented 11 months ago

Had to rollback to 2.0.0 and it works now so something broke between 2.0.0 and 2.1.2

Secreto31126 commented 11 months ago

Huh, that's weird. Let me check if I can replicate the issue.

Secreto31126 commented 11 months ago

The only "big" change between 2.0.0 and 2.1.0 was the addition of "sideEffects": false to the package.json, which might have broken the messages/index.ts imports accidentally.

Would you mind trying out this beta release?

npm i whatsapp-api-js@2.0.1-beta.0

That release is exactly the same as v2 except for the side effects property. If it breaks too, it's definitely the reason.

HysMX commented 11 months ago

Working with 2.0.1-beta.0

Secreto31126 commented 11 months ago

Wow, ok, that's absolutely unexpected.

Let's keep scaling. 2.1.0 contains almost no code change, most of the files are documentation and CI/CD. The only ts files changed were index.ts, template.ts and types.ts, so I expect it to work too.

npm i whatsapp-api-js@2.1.0
Secreto31126 commented 10 months ago

Do you want to try out 2.1.3-beta.0? I removed the sideEffects property from package.json

HysMX commented 10 months ago

image 2.1.3-beta.0 still says that

Secreto31126 commented 10 months ago

I will close this as solved. The issue was a mismatching package and tsconfig.

For future reference, I recommend using the library with "type": "module" in package.json and "target": "es6", "module": "nodenext" and "skipLibCheck": true in tsconfig.json, specially since CJS support might be dropped in the future.