Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of null (reading 'version') error #3242

Closed
1 task done
Crecheer opened this issue Dec 10, 2023 · 3 comments
Closed
1 task done

Cannot read properties of null (reading 'version') error #3242

Crecheer opened this issue Dec 10, 2023 · 3 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@Crecheer
Copy link

Crecheer commented Dec 10, 2023

  • The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.14.0
  • server: vanilla 1.20.1
  • node: 20.10.0

Detailed description of a problem

The Bot isnt starting because of an error which i cant fix.

What did you try yet?

I tried many examples from other people but each had the same error, i also tried on offline and online servers but it still dosent work:

    const version = require('minecraft-data')(bot._client.version).version
                                                                  ^

TypeError: Cannot read properties of null (reading 'version')
    at next (C:\Users\jan\mcbot\node_modules\mineflayer\lib\loader.js:108:67)
    at Object.createBot (C:\Users\jan\mcbot\node_modules\mineflayer\lib\loader.js:105:34)
    at Object.<anonymous> (C:\Users\jan\mcbot\index.js:4:24)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Your current code

const mineflayer = require('mineflayer')
const data = require('minecraft-data')

const bot = mineflayer.createBot({
  host: 'localhost',
  port: 25565,
  username: 'bot',
  auth: 'offline',
  version: '1.20'
})


bot.on('login', () => {
  console.log("Logged in")
})

Expected behavior

The bot starts, and writes "Logged in" into the console

Additional context

Win 11, kinda new to js, i did more html + js

@Crecheer Crecheer added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Dec 10, 2023
@SilianZ
Copy link
Contributor

SilianZ commented Dec 10, 2023 via email

@amoraschi
Copy link
Contributor

The proper way to require minecraft-data is like this:

const data = require('minecraft-data')(bot.version)

There are examples that show how to do it.
Alternatively you can use bot.registry to access minecraft-data directly without having to require it.
Close issue if solved.

@extremeheat
Copy link
Member

In this case, it seems the error is because you are specifying 1.20 as version but your packages have not been updated to support 1.20.

Please run npm update --depth 9999 and remove the version field -- it can be chosen automatically. Just keep in mind mineflayer does not support 1.20.2+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

4 participants