amoraschi / mineflayer-elytrafly

Plugin for Mineflayer bots to make them fly (i.e. blatantly cheat)
9 stars 1 forks source link

How can I import this plugin? #2

Closed TacticalSpoon331 closed 2 years ago

TacticalSpoon331 commented 2 years ago

Error thrown when importing plugin:

const elytrafly = require('mineflayer-elytrafly') ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/mineflayer-elytrafly/dist/index.js from elytraTest.js not supported. Instead change the require of index.js in elytraTest.js to a dynamic import() which is available in all CommonJS modules. at Object. (elytraTest.js:2:19) { code: 'ERR_REQUIRE_ESM' }

amoraschi commented 2 years ago

It uses ES6 syntax, so you should import it like this:

import { elytrafly } from 'mineflayer-elytrafly'
TacticalSpoon331 commented 2 years ago

Now I just get:

(node:13219) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (Use node --trace-warnings ... to show where the warning was created) elytraTest.js:2 import { elytrafly } from 'mineflayer-elytrafly' ^^^^^^

SyntaxError: Cannot use import statement outside a module

Sorry, trying to relearn JS

amoraschi commented 2 years ago

The error tells you what to do, part of learning a language is learning to understand errors

TacticalSpoon331 commented 2 years ago

Not trying to be that guy that goes straight to GitHub without investigating any errors first. I tried marking the script as a module but that just led to more problems. This might be asking too much but are there any example projects I could take a look at to make sure it's not my node installation?

amoraschi commented 2 years ago

It's not your Node installation, what's your error?