ОШИБКА в node-telegram-bot-api Модуль не найден: не удается разрешить 'fs', 'net', 'tls' в node-telegram-bot-api - PullRequest
0 голосов
/ 04 января 2019

    ERROR in ./node_modules/mime/mime.js
    Module not found: Error: Can't resolve 'fs' in 'my-project\node_modules\mime'
     @ ./node_modules/mime/mime.js 2:9-22
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/node-telegram-bot-api/lib/telegramWebHook.js
    Module not found: Error: Can't resolve 'fs' in 'my-project\node_modules\node-telegram-bot-api\lib'
     @ ./node_modules/node-telegram-bot-api/lib/telegramWebHook.js 11:9-22
     @ ./node_modules/node-telegram-bot-api/lib/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/node-telegram-bot-api/lib/telegram.js
    Module not found: Error: Can't resolve 'fs' in 'my-project\node_modules\node-telegram-bot-api\lib'
     @ ./node_modules/node-telegram-bot-api/lib/telegram.js 31:9-22
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/node-telegram-bot-api/src/telegram.js
    Module not found: Error: Can't resolve 'fs' in 'my-project\node_modules\node-telegram-bot-api\src'
     @ ./node_modules/node-telegram-bot-api/src/telegram.js 17:11-24
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/node-telegram-bot-api/src/telegramWebHook.js
    Module not found: Error: Can't resolve 'fs' in 'my-project\node_modules\node-telegram-bot-api\src'
     @ ./node_modules/node-telegram-bot-api/src/telegramWebHook.js 5:11-24
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/request/lib/har.js
    Module not found: Error: Can't resolve 'fs' in 'my-project\node_modules\request\lib'
     @ ./node_modules/request/lib/har.js 3:9-22
     @ ./node_modules/request/request.js
     @ ./node_modules/request/index.js
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/forever-agent/index.js
    Module not found: Error: Can't resolve 'net' in 'my-project\node_modules\forever-agent'
     @ ./node_modules/forever-agent/index.js 6:10-24
     @ ./node_modules/request/request.js
     @ ./node_modules/request/index.js
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/tough-cookie/lib/cookie.js
    Module not found: Error: Can't resolve 'net' in 'my-project\node_modules\tough-cookie\lib'
     @ ./node_modules/tough-cookie/lib/cookie.js 32:10-24
     @ ./node_modules/request-promise/lib/rp.js
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/tunnel-agent/index.js
    Module not found: Error: Can't resolve 'net' in 'my-project\node_modules\tunnel-agent'
     @ ./node_modules/tunnel-agent/index.js 3:10-24
     @ ./node_modules/request/lib/tunnel.js
     @ ./node_modules/request/request.js
     @ ./node_modules/request/index.js
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/forever-agent/index.js
    Module not found: Error: Can't resolve 'tls' in 'my-project\node_modules\forever-agent'
     @ ./node_modules/forever-agent/index.js 7:10-24
     @ ./node_modules/request/request.js
     @ ./node_modules/request/index.js
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js

    ERROR in ./node_modules/tunnel-agent/index.js
    Module not found: Error: Can't resolve 'tls' in 'my-project\node_modules\tunnel-agent'
     @ ./node_modules/tunnel-agent/index.js 4:10-24
     @ ./node_modules/request/lib/tunnel.js
     @ ./node_modules/request/request.js
     @ ./node_modules/request/index.js
     @ ./node_modules/node-telegram-bot-api/src/telegram.js
     @ ./node_modules/node-telegram-bot-api/index.js
     @ ./client/index.js
    
<pre>
import React, { Component } from "react";
import { render } from "react-dom";
import Home from "./components/Home.jsx";

const TelegramBot = require('node-telegram-bot-api');
const token = "MY_TOKEN";
const bot = new TelegramBot(token, {polling: true});

render(Home, document.getElementById("root"));

1 Ответ

0 голосов
/ 04 января 2019

Вы не можете использовать require в приложении браузера (например, реагировать).require для приложений node.js, только выполните import.

Этот бот-телеграмма, похоже, требует доступа к файловой системе (fs), и он в любом случае недоступен в браузере, поэтому вы выигралине могу использовать его напрямую во внешнем интерфейсе.

Извините за плохие новости.

...