E
E
Egor2020-09-24 16:08:18
In contact with
Egor, 2020-09-24 16:08:18

VK bot won't start on Node JS?

Good afternoon, I decided to try to make a bot on Node.Js. I found the VK-IO library, copied the example from the documentation, but it doesn't work, tell me what I'm doing wrong?

Mistake:

/home/vk_bot/app.js:1
import { VK } from 'vk-io';
^^^^^^

SyntaxError: Cannot use import statement outside a module


The code:
import { VK } from 'vk-io';

const vk = new VK({
  token: process.env.TOKEN
});

vk.updates.on('message_new', async (context) => {
  if (context.text === 'Привет') {
    await context.send('Привет!');
  }
});

await vk.updates.start();


Documentation from which I took the example:
https://negezor.github.io/vk-io/en/guide/modules.h...

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cython, 2020-09-24
@KenKup11

You are using an example that uses es6 modules which nodejs does not support. You need to use the CommonJS import.
PS: learn to fully read the documentation
const { VK } = require('vk-io');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question