The question is published on by Tutorial Guruji team.
I have a discord bot, on my premises (Windows 10) it works correctly, but on the server (Ubuntu Server 20) it gives me the following error.
The error occurs when I receive a chat message from the server, that is, for example, on my computer, I would read the message and reply to it, on the server, I get the error.
(node:657201) UnhandledPromiseRejectionWarning: TypeError: (intermediate value).flatMap is not a function at Promise.all.events.map (/root/discordbot/node_modules/@typeit/src/logic/metadatas/MetadataStorage.ts:155:14) at process._tickCallback (internal/process/next_tick.js:68:7) (node:657201) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:657201) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.`
It’s the same project, the same everything, I don’t know what can happen.
Answer
.flat()
and .flatMap
are only available on Node >= 11
Seems like you are using Node 10, try upgrading your Node to version 11+
You can use nvm, install by running this command
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
then run nvm install node
,
this will install latest node version, you can also specify the version like this
nvm install 12.16.3
then use the version, to use the latest version, run nvm use node
or to use specific installed version, run nvm install 12.16.3
Then verify your node version by running node -v