RainEggplant / chatgpt-telegram-bot

A ChatGPT bot for Telegram based on Node.js. Support both browserless and browser-base APIs.
MIT License
323 stars 97 forks source link

Support Node.js v19 #14

Closed VectorZhao closed 1 year ago

VectorZhao commented 1 year ago

I want to use docker to build this project, but there is no .env file. Did you forget to add it to the project?

VectorZhao commented 1 year ago

I created a node container and when I run command pnpm install I got the following error:

root@chatgpt:/home/chatgpt-tg-bot# pnpm install
Lockfile is up to date, resolution step is skipped
Packages: +470
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are cloned from the content-addressable store to the virtual store.
  Content-addressable store is at: /home/chatgpt-tg-bot/.pnpm-store/v3
  Virtual store is at:             node_modules/.pnpm
Downloading registry.npmmirror.com/typescript/4.9.5: 11.6 MB/11.6 MB, done
Progress: resolved 470, reused 0, downloaded 470, added 470, done
node_modules/.pnpm/registry.npmmirror.com+puppeteer@19.7.1_typescript@4.9.5/node_modules/puppeteer: Running postinstall script, failed in 3.7s
.../node_modules/puppeteer postinstall$ node install.js
│ The chromium binary is not available for arm64.
│ If you are on Ubuntu, you can install with: 
│  sudo apt install chromium
│  sudo apt install chromium-browser
│ ERROR: Failed to set up Chromium r1095492! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
│ Error
│     at handleArm64 (/home/chatgpt-tg-bot/node_modules/.pnpm/registry.npmmirror.com+puppeteer-core@19.7.1_typescript@4.9.5/node_modul
│     at BrowserFetcher.download (/home/chatgpt-tg-bot/node_modules/.pnpm/registry.npmmirror.com+puppeteer-core@19.7.1_typescript@4.9.
│     at async downloadBrowser (/home/chatgpt-tg-bot/node_modules/.pnpm/registry.npmmirror.com+puppeteer@19.7.1_typescript@4.9.5/node_
└─ Failed in 3.7s at /home/chatgpt-tg-bot/node_modules/.pnpm/registry.npmmirror.com+puppeteer@19.7.1_typescript@4.9.5/node_modules/puppeteer
 ELIFECYCLE  Command failed with exit code 1.

The api.type in local.json file has been set to unofficial.

VectorZhao commented 1 year ago
root@chatgpt:/home/chatgpt-tg-bot# pnpm install
Lockfile is up to date, resolution step is skipped
Packages: +470
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are cloned from the content-addressable store to the virtual store.
  Content-addressable store is at: /home/chatgpt-tg-bot/.pnpm-store/v3
  Virtual store is at:             node_modules/.pnpm
Downloading registry.npmmirror.com/typescript/4.9.5: 11.6 MB/11.6 MB, done
Progress: resolved 470, reused 0, downloaded 470, added 470, done
node_modules/.pnpm/registry.npmmirror.com+puppeteer@19.7.1_typescript@4.9.5/node_modules/puppeteer: Running postinstall script, done in 8.8s

dependencies:
+ chatgpt 4.5.1
+ chatgpt-v3 <- chatgpt 3.5.1
+ config 3.3.9
+ dotenv 16.0.3
+ lodash 4.17.21
+ node-telegram-bot-api 0.60.0
+ puppeteer 19.7.1

devDependencies:
+ @types/config 3.3.0
+ @types/lodash 4.14.191
+ @types/node 18.14.0
+ @types/node-telegram-bot-api 0.57.7
+ @typescript-eslint/eslint-plugin 5.52.0
+ @typescript-eslint/parser 5.52.0
+ eslint 8.34.0
+ eslint-config-prettier 8.6.0
+ husky 8.0.3
+ lint-staged 13.1.2
+ prettier 2.8.4
+ tsc-watch 6.0.0
+ typescript 4.9.5

> chatgpt-telegram-bot@2.1.0 prepare /home/chatgpt-tg-bot
> husky install

husky - Git hooks installed

Done in 3m 57.1s
root@chatgpt:/home/chatgpt-tg-bot# pnpm build && pnpm start

> chatgpt-telegram-bot@2.1.0 build /home/chatgpt-tg-bot
> tsc --build

> chatgpt-telegram-bot@2.1.0 start /home/chatgpt-tg-bot
> node --experimental-specifier-resolution=node dist/index.js

node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/chatgpt-tg-bot/dist/api' imported from /home/chatgpt-tg-bot/dist/index.js
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:231:11)
    at moduleResolve (node:internal/modules/esm/resolve:850:10)
    at defaultResolve (node:internal/modules/esm/resolve:1058:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:416:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v19.6.1
 ELIFECYCLE  Command failed with exit code 1.
RainEggplant commented 1 year ago

I created a node container and when I run command pnpm install I got the following error:

root@chatgpt:/home/chatgpt-tg-bot# pnpm install
[...]
│ The chromium binary is not available for arm64.
[...]
│ ERROR: Failed to set up Chromium r1095492! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
[...]

As the error message indicates, puppeteer did not find a chromium browser binary for the arm64 platform. You can set "PUPPETEER_SKIP_DOWNLOAD" environmental variable to skip downloading the browser.

VectorZhao commented 1 year ago

I created a node container and when I run command pnpm install I got the following error:

root@chatgpt:/home/chatgpt-tg-bot# pnpm install
[...]
│ The chromium binary is not available for arm64.
[...]
│ ERROR: Failed to set up Chromium r1095492! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
[...]

As the error message indicates, puppeteer did not find a chromium browser binary for the arm64 platform. You can set "PUPPETEER_SKIP_DOWNLOAD" environmental variable to skip downloading the browser.

yeah, I have done. But Error [ERR_MODULE_NOT_FOUND] as I mentioned above stopped me.

RainEggplant commented 1 year ago

[...]
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/chatgpt-tg-bot/dist/api' imported from /home/chatgpt-tg-bot/dist/index.js
[...]
Node.js v19.6.1

Node.js v19 has removed the --experimental-specifier-resolution flag (https://github.com/nodejs/node/pull/44859). I'll use a custom loader to achieve a similar function.

RainEggplant commented 1 year ago

Fixed by e35075a