Error: You need to call Parse.initialize before using Parse

Hi members!
I was working on a project built with Parse.
Now after a while, I come to do some changes.
But, I have an error for running Parse. It says I need to initialize it first.
I initialize it before use it. Like this:

import Parse from "parse";

Parse.initialize(process.env.APP_ID, process.env.MASTER_KEY);
Parse.serverURL = process.env.SERVER_URL;
Parse.masterKey = process.env.MASTER_KEY;

export default Parse;

And I will use the exported Parse from this file and use it in my app. I’m a little confused because it was working fine a while ago (:

What is the line of code that is throwing that error message?

Almost every where I imported Parse from the initial file. Like this picture:

You need to make sure that your initialization code runs before the other files.

So, how can I make sure of that? Because it was fine earlier.

I tried to make it a function that exports an initialized Parse when calling it. Not sure about this approach, but this is the code:

function initialize() {
	Parse.initialize(process.env.APP_ID, process.env.MASTER_KEY);
	Parse.serverURL = serverUrl;
	Parse.masterKey = process.env.MASTER_KEY;

	return Parse;
}

export default initialize;

and in other files to something like this:

import Parse from "lib/parse";

...

Parse().Config.get()

But the same result again.

It really depends on the framework you are using, but you need to make sure that initialize() function is called since the app is loaded and before any other call to Parse.

I’m using Next.js as my framework. And I’m using the non-nodejs version of Parse. Do you think calling it in _app.js would be enough?

Calling in _app.js should fix the issue. Also it is importante to check whether the code is running in browser or node and load the appropriate sdk.