MafiaHub / Framework

Advanced modding framework for multiplayer modifications
https://mafiahub.dev
Other
37 stars 7 forks source link

Can't import another JS file in the main one #86

Closed Deewarz closed 6 months ago

Deewarz commented 6 months ago

Example

// other.js
console.log("Hello");
// index.js
import "other";

Error log

[18:24:55] [debug] [Scripting] [Helpers] exception at gamemode/index.js: 1
[18:24:55] [debug] [Scripting] [Helpers] import "other";
[18:24:55] [debug] [Scripting] [Helpers] SyntaxError: Cannot use import statement outside a module
[18:24:55] [debug] [Scripting] Invalid gamemode script object
hurfy commented 6 months ago

This syntax is not supported, you need to use another option:

// index.js
const vehicles = require("./src/code/vehicles.js");
// ./src/code/vehicles.js
console.log("Hello from vehicles.js");

output: image

Deewarz commented 6 months ago

Ah yes, CommonJS!

My bad, thank you!

Segfaultd commented 6 months ago

That's something we will address once everything else is stabilized, but for now you'd have to stick to CommonJS