Zain-ul-din / whatsapp-ai-bot

This is a WhatsApp AI bot that uses various AI models, including Gemini, GPT, DALL-E, and StabilityAI, to generate responses to user input.
https://wa-ai-seven.vercel.app/
MIT License
161 stars 89 forks source link

Error: Invalid environment; fetch is not defined #8

Closed alvlp-xyz closed 1 year ago

alvlp-xyz commented 1 year ago

 sh setup.sh installing dependencies Need to install the following packages: yarn@1.22.19 Ok to proceed? (y) y yarn install v1.22.19 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... Done in 47.12s. npm notice npm notice New major version of npm available! 8.19.2 -> 9.7.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.7.2 npm notice Run npm install -g npm@9.7.2 to update! npm notice ✔ dependencies has been installed initializing server yarn run v1.22.19 $ vite-node ./src/index.ts 🤖 starting client... file:///home/runner/whatsapp-ai-bot/node_modules/chatgpt/build/index.js:174 throw new Error("Invalid environment; fetch is not defined"); ^

Error: Invalid environment; fetch is not defined at new ChatGPTAPI (file:///home/runner/whatsapp-ai-bot/node_modules/chatgpt/src/chatgpt-api.ts:107:13) at new ChatGptModel (/home/runner/whatsapp-ai-bot/src/models/ChatGptModel.ts:15:23) at new WhatsAppClient (/home/runner/whatsapp-ai-bot/src/lib/WhatsAppClient.ts:36:42) at /home/runner/whatsapp-ai-bot/src/index.ts:4:24 at ViteNodeRunner.directRequest (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/client.mjs:312:5) at ViteNodeRunner.cachedRequest (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/client.mjs:156:14) at ViteNodeRunner.executeFile (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/client.mjs:133:12) at CAC.run (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/cli.mjs:70:5) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Zain-ul-din commented 1 year ago

@alvlp-xyz which node js version you're using?

to check your node js version open the terminal and type

node -v

image

It is worth noting, If you're using a version of Node prior to 18, the is not implemented out-of-the-box.

Solution

Simply upgrade your node js version to current LTS version.

zain-ul-din-zafar commented 1 year ago

In case you're deploying an app to railway or somewhere else. They are likely using NixPack to set the node js version of your choice in this case version 18.

set NIXPACKS_NODE_VERSION environment variable to 18


[Setup#](https://nixpacks.com/docs/providers/node#setup)
The following major versions are available

14
16 (Default)
18
The version can be overridden by

Setting the NIXPACKS_NODE_VERSION environment variable
Specifying the engines.node field in package.json
Only a major version can be specified. For example, 14.x or 14.

Copied from Nixpacks.com