skip to Main Content

I recently downloaded and installed Telegraf – telegram bot api. It works with Node.js. I looked at 17 sites, including github, and did not find a solution for myself.

Here is the error:

node .srcbot.js
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'C:ProjectsTelegramsrcbot.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

And my code for bot.js:

const Telegraf = require('telegraf')

const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start((ctx) => ctx.reply('Welcome!'))
bot.launch()

My system: Windows 10 64bit

IDE: Visual Studio Code 1.38.1

Node version: 10.16.3

Npm version: 6.11.3

Please do not give me links to the solution found from Google. I tried it over 100 times. If you understand, help me. Thanks

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution myself! It turns out the case in the file name. Since the folder is called "bot" and the file inside is also "bot.js". This gives a name conflict.

    Solution

    Rename file bot.js to tg-bot.js


  2. Hey bro I solved the problem first run the code on cmd using node bot.js command where bot.js is the file name and current directory is directory containing bot.js

    If the error occurs just give npm install telegraf and the problem is solved

    This is true for any module not found errors replace telegraf with the module that is missing in your case.

    Good day!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search