Baileys
Baileys copied to clipboard
[BUG] TypeScript error - Cannot find module '@adiwajshing/baileys' or its corresponding type declarations.
Describe the bug
On the import line it gives me an error - Cannot find module '@adiwajshing/baileys' or its corresponding type declarations.
import makeWASocket, {DisconnectReason, makeInMemoryStore, isJidGroup, useMultiFileAuthState} from '@adiwajshing/baileys'
The same line worked fine with the previous repo, adiwajshing/baileys
To Reproduce Steps to reproduce the behavior:
- Install the library as dependency in TS project -
yarn add github:WhiskeySockets/Baileys
- Run
npm run build
(I'm usingnest
for that) - Observe the error.
Expected behavior It works :)
Environment (please complete the following information):
- node 18
- yarn 1.22
- typescript 4.7.4
- What else could help here?
Additional context
The same code with adiwajshing/baileys
dependency from node_modules
works fine. No changes made.
If I suppress it with // @ts-ignore
it shows
Error: Cannot find module '/home/allburov/git/project/node_modules/@adiwajshing/baileys/lib/index.js'. Please verify that the package.json has a valid "main" entry
uses npm, using yarn you need to run tsc manually.
If I suppress it with
// @ts-ignore
it showsError: Cannot find module '/home/allburov/git/project/node_modules/@adiwajshing/baileys/lib/index.js'. Please verify that the package.json has a valid "main" entry
I am facing the same error after tweaking for this git.
npm i https://github.com/WhiskeySockets/Baileys --force
It'd be good if I can use npm
instead of yarn
, but it doesn't seem possible - npm gives me too much errors and with yarn project (the rest) works perfectly :(
For now I cloned the git repo, installed, compiled and added it to my package with yarn add file:../Baileys
:+1:
I hope you'll be able to deploy the library in https://www.npmjs.com/ soon!
npm i https://github.com/WhiskeySockets/Baileys --force
I was unsuccessful in the attempt.
OK, do the following.
1- delete the node modules
2- delete the package.lock
3- run -> yarn install.
4 - verify https ->"@adiwajshing/baileys": https://github.com/WhiskeySockets/Baileys
5- clear npm cache
I had the same error, when I did that it started working again and recognizing normally
OK, do the following.
1- delete the node modules
2- delete the package.lock
3- run -> yarn install.
4 - verify https ->"@adiwajshing/baileys": https://github.com/WhiskeySockets/Baileys
I had the same error, when I did that it started working again and recognizing normally
What is "verify https" meant? What is that?
I meant that it is necessary in dependencies of package.json that have https to reference the repository.
well... that's what worked for me.
uses npm, using yarn you need to run tsc manually.
You need to also tsc manually in npm
OK, do the following.
1- delete the node modules
2- delete the package.lock
3- run -> yarn install.
4 - verify https ->"@adiwajshing/baileys": https://github.com/WhiskeySockets/Baileys
I had the same error, when I did that it started working again and recognizing normally
Use "@adiwajshing/baileys": "github: WhiskeySockets/Baileys",
I have this same issue too
I just trying to change the import path and show this error
import makeWASocket from './Socket'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1055:15)
at Module._compile (node:internal/modules/cjs/loader:1090:27)
There's my script
import makeWASocket, { DisconnectReason, UserFacingSocketConfig } from '@adiwajshing/baileys/src'
import { Boom } from '@hapi/boom'
async function connectToWhatsApp () {
const sock = makeWASocket({
// can provide additional config here
printQRInTerminal: true
} as UserFacingSocketConfig)
sock.ev.on('connection.update', (update: any) => {
const { connection, lastDisconnect } = update
if(connection === 'close') {
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
// reconnect if not logged out
if(shouldReconnect) {
connectToWhatsApp()
}
} else if(connection === 'open') {
console.log('opened connection')
}
})
sock.ev.on('messages.upsert', async (m: any) => {
console.log(JSON.stringify(m, undefined, 2))
console.log('replying to', m.messages[0].key.remoteJid)
await sock.sendMessage(m.messages[0].key.remoteJid!, { text: 'Hello there!' })
})
}
// run in main file
connectToWhatsApp()
I had the same problem, I just cleared the cache and it worked
yarn cache clean
Now you can install using npm install @whiskeysockets/baileys
or yarn add @whiskeysockets/baileys
- https://whiskeysockets.github.io/docs/intro
You can use the git version using NPM or Yarn V2, the Yarn v1 (classic) will not work.
You can use the git version using NPM or Yarn V2, the Yarn v1 (classic) will not work.
For those who (as me) didn't know about that - you must run the command below to set V2 mode
yarn set version berry
after that yarn add github:WhiskeySockets/Baileys
works fine!