mullwar / telebot

The easy way to write Telegram bots in Node.js
https://www.npmjs.com/package/telebot
MIT License
1.48k stars 270 forks source link

Warning on compilation with electron-webpack (and webpack-dev-server) #153

Open SwiTool opened 5 years ago

SwiTool commented 5 years ago

Telebot version: ^1.2.6

I get this warning when I import the Telebot module:

  WARNING in ./node_modules/telebot/lib/telebot.js
  74:63-117 Critical dependency: the request of a dependency is an expression
   @ ./node_modules/telebot/lib/telebot.js
   @ ./src/renderer/main/bot/util/Notifications/Telegram.js
   @ ./src/renderer/main/bot/Bot.js
   @ ./src/renderer/main/app/App.js
   @ ./src/renderer/main/index.js
   @ ./src/renderer/index.js
   @ multi (webpack)-dev-server/client?http://localhost:9080 webpack/hot/dev-server ./src/renderer/index.js

  WARNING in ./node_modules/telebot/lib/telebot.js
  77:56-99 Critical dependency: the request of a dependency is an expression
   @ ./node_modules/telebot/lib/telebot.js
   @ ./src/renderer/main/bot/util/Notifications/Telegram.js
   @ ./src/renderer/main/bot/Bot.js
   @ ./src/renderer/main/app/App.js
   @ ./src/renderer/main/index.js
   @ ./src/renderer/index.js
   @ multi (webpack)-dev-server/client?http://localhost:9080 webpack/hot/dev-server ./src/renderer/index.js

It prevents me from running my app. I'm using electron-webpack (default configuration) here are the babel plugins / preset :

    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-react": "^6.24.1",

I have something similar with another Telegram library. What's wrong please? https://github.com/telegraf/telegraf/issues/511

SwiTool commented 5 years ago

It works by replacing this :

        // Load build-in plugins
        this.buildInPlugins.map(buildInPluginName => this.plug(require('this.buildInPluginsFolder + buildInPluginName')));

        // Load user plugins
        this.usePlugins.map(userPluginName => this.plug(require('this.pluginFolder + userPluginName')));

into this :

        // Load build-in plugins
        this.buildInPlugins.map(buildInPluginName => this.plug(require(`${this.buildInPluginsFolder}${buildInPluginName}`)));

        // Load user plugins
        this.usePlugins.map(userPluginName => this.plug(require(`${this.pluginFolder}${userPluginName}`)));

PR : https://github.com/mullwar/telebot/pull/154