MZ Import Javascript file inside a plugin

Hello,

I'm learning how to make a plugin, and I would like to know how to import javascript files inside a plugin.
When I do it with import it says :
cannot import statement outside a module
cf my js sample

JavaScript:
/**
 * utilities function for global event
 *
 * @target MZ
 */
import { Vector2 } from './BE_Vector2.js'; // here is my non working import
var Imported = Imported|| {};

var BE = BE || {};
BE.Util = BE.Util || {};

(() => {
    const pluginName = "BE_GlobalEvents";
    const VarMoveTimer = 1;
    const PlayerLastTile = 2;
    const PlayerCurrentTile = 3;

    var __lastKnownPosition = Vector2(-1, -1);

    BE.Util.logVariables = function (interpreter) {
        $gameVariables.setValue(PlayerCurrentTile, 'It works');
    }
    BE.Util.isLastPositionChanged = function (interpreter) {             
        currentPos = Vector2($gamePlayer.x, $gamePlayer.y);
        if (__lastKnownPosition.equal(currentPos) != true) {
            __lastKnownPosition = currentPos;
            return true;
        }
        return false;
            
    }
})();

Thanks for the answers !
What's the point of the importing? If the other file is in the plugin folder and included as a plugin, you can freely reference its code in other files.
I have some development background, but not so much in Javascript, nor rpg maker ecosystem, I may not know obvious thing, for exemple
you can freely reference its code in other files [when register as a plugin]
so thanks for that!

and my objective it's to have utilities function/variable accessible only for my plugin without having to register each files as a plugin
In my specific case I wan't to add Vector2 data structure
Someone with more technical JavaScript knowledge may be able to help, but the error message is telling me you can't use that command because plugin files are not structured as modules. From my quick looking up of it, that seems like it's used for JavaScript that's embedded in Web pages.

So you either include that as a plugin and reference it, or...it's only 95 lines. Just start writing your plugin beneath it (or copy that code into yours).
So after more digging I found a solution that satisfy me:

from the includer:
JavaScript:
/**
 * utilities function for global event
 *
 * @target MZ
 */


var Imported = Imported|| {};

var BE = BE || {};
BE.Util = BE.Util || {};

(() => {
   
const BE_Vector2 = require("js/plugins/BillyEngine/BE_Vector2.js")
//...
var __lastKnownPosition = new BE_Vector2(-1, -1);
// bla bla more code doing more stuff

from the included:

JavaScript:
var Vector2 = function (x, y) {
    this.x = (x === undefined) ? 0 : x;
    this.y = (y === undefined) ? 0 : y;
}

Vector2.prototype.set = function(x, y) {
    this.x = x || 0;
    this.y = y || 0;
}
// ...
module.exports = Vector2;

The critical aspect for the solution is rmmz and rmmv use NodeJS behind the scene, that means you'll have to use its specificity. You'll find my sources below

Hope it helps someone !

source:
forum rpgmaker: Best practices for a plugin using multiple files
stackoverflow: In Node.js, how do I "include" functions from my other files?
Btw. There's a raw javascript way to do it. And it's literally how MV and MZ load plugins.

Code:
PluginManager.loadScript = function(name) {
    var url = this._path + name;
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    script.async = false;
    script.onerror = this.onError.bind(this);
    script._url = url;
    document.body.appendChild(script);
};

so you'd simply call this function.

Original thread: https://forums.rpgmakerweb.com/threads/import-javascript-file-inside-a-plugin.169413/