How to Import js file into doctype js files?

I have some common functions, which I have put in /app/public/js/file.js

I am using frappe.require() and it’s not showing any error, meaning it is taking the path correctly and when I am doing console.log() inside the file to check if its loaded, it is correct.

But my functions inside the file, when I am trying to call them, I am getting function not defined error in console.

What could be the reason for it?

Frappe.require is loading my file at the end. I want to load it at the starting, How to correct that?

frappe.require will be async so whatever code that you need to execute after loading JS has to be done in callback or using returned promise.

frappe.require("path").then(() => {
    // only in this scope and code that runs after it will have access to what you imported.
})

Example:

Any way to lead it in sync??

Or other way to import js file?