Jump to content

Migrating from 0.3.7 to 1.1 JS need help!


dominion

Recommended Posts

I am trying to migrate a build from 0.3.7 to 1.1 and faced such a problem. I get an error when starting server 1.1

[ERROR] "server" package loading failed, exception stack: TypeError: global.require is not a function at Object. <anonymous> (C: \ RAGEMP \ server-files \ packages \ server \ index.js: 1: 17)

here is the code:

let fs = global.require('fs');
let path = global.require('path');
let domain = require('domain');
let serverDomain = domain.create();
let async = require('async');
let walk = require('parallel-walker');
let folder = './packages/configs/';
let world = require('./mongodb/world.js').world;
let loadConfigsVehicles = require('./a/functions/vehicle/configsVehicles.js').load;

serverDomain.on('error',function (err) {
    console.error(err.message)
})

function getDirectories(srcpath) {
    return fs.readdirSync(srcpath).filter(file => {
        return fs.statSync(path.join(srcpath, file)).isDirectory();
    });
}

mp.configs = {}
let loadConfigs = (callback)=>{
    let walker = walk.create();
    let files = [];
    let loadFiles = [];
	walker.on("file", function (file) {
		if(path.extname(file) == '.json'){
            files.push(file);
		}
	});
	walker.on("errors", function (error) {
		callback(error);
	});
	walker.on("end", function () {
        files.forEach((file,i)=>{
            fs.readFile(file, 'utf8', function (err, text) {
                if (err) throw err;
                try{
                    let data = JSON.parse(text);
                    let fileName = path.basename(file).replace(path.extname(file),'');
                    if(data.isglobal === false) return; 
                    data.save = ()=>{
                        let save = JSON.stringify(mp.configs[fileName]);
                        if(mp.configs[fileName].minemaized === false)save = JSON.stringify(mp.configs[fileName],null,4);
                        fs.writeFile(file, save, 'utf8', (err)=>{
                            console.log('Конфиг с названием '+fileName+' сохранён')
                        });
                    }
                    mp.configs[fileName] = data;
                    loadFiles.push(fileName)
                    if(loadFiles.length == files.length)callback();
                }catch(e){
                    console.error(e)
                }
            });
        });
	});
	walker.walk(folder);
}

let loadWorldModel = (callback)=>{
	world.find({},(err,done)=>{
		if(done.length == 0){
			let s = new world();
			s.save().catch((err)=>{
				console.error(err)
			}).then((data)=>{
				add_world(data);
				callback(err)
			})
		}else{
			add_world(done[0])
			callback(err)
		}
	})
}
console.time('LoadServer')
async.parallel([
    loadConfigs,
    loadWorldModel,
    loadConfigsVehicles
],(err)=>{
	if(err)console.log(err)
    serverDomain.run(()=>{
        getDirectories('packages/server').forEach(src => {
            try {
				global.require('./packages/server/' + src);
            } catch (e) {
                console.error('Error: ' + e.stack);
            }
        });
        console.timeEnd('LoadServer')
    })
})

If i just remove global. i ve got

[DONE] The server is ready to accept connections.
Succesfully connected to MongoDB Database
Error: Error: Cannot find module './packages/server/a'
Require stack:
- C:\RAGEMP\server-files\packages\server\index.js
- C:\RAGEMP\server-files\bin\loader.mjs

 

On 0.3.7 everything works fine

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...