Repository: next.js
Issue: Need support referring same singleton between different page's `getStaticProps` during building time.
Labels: bug,Module Resolution

### Link to the code that reproduces this issue

https://github.com/PrinOrange/need-support-singleton-for-different-page.git

### To Reproduce

1. Create a ts module, and set and export a singleton, which needs time-costing initializing.
```ts
const buildMySingleton = async ():Promise<{value:string}> => {
  return new Promise((resolve) => {
    console.log("\nStart initializing my singleton");

    // Here is a progress of initializing singleton that costs much time
    setTimeout(() => {
      resolve({ value: "data" });
    }, 20000);
  });
};

export const MySingleton = await buildMySingleton();
```
2. Refer this singleton in different page's `getStaticProps`.

In PageA,
```ts
import { MySingleton } from "../lib/my-module";
export default function PageA(props) {
  return <div>PageA</div>;
}
export const getStaticProps = () => {
  const mySingleton = MySingleton;  // refer the singleton
  return { props: { value: mySingleton.value } };
};
```
And in PageB
```ts
import { MySingleton } from "../lib/my-module";
export default function PageB(props) {
  return <div>PageB</div>;
}
export const getStaticProps = () => {
  const mySingleton = MySingleton; // refer the singleton
  return { props: { value: mySingleton.value } };
};
```

And so on, refer this singleton in different pages

4. Run `npm run build` to build the next.js project
5. I find that the terminal outputs `Start initializing my singleton` many times

![image](https://github.com/user-attachments/assets/887d6646-a9d6-4090-9f22-529010e8b707)

This means that in the SSG process of different pages, each page will initialize its own `MySingleton`, and not use the same `MySingleton`.

This will lead to a problem: if initializing `MySingleton` is a very time-consuming process, each page will generate its own `MySingleton`, and this unnecessary multiple initialization will seriously slow down the build performance.

In addition, and more seriously: if initializing the Singleton is not an idempotent operation (such as connecting to a database), then this will cause errors to occur.

### Current vs. Expected behavior

My purpose is set a singleton in a module, and every page's `getStaticProps` should use same one singleton during building time. It means that the module singleton is supposed to be initialized once. Because the singleton initializing is very time-costing.

### Provide environment information

```bash
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 36670
  Available CPU cores: 8
Binaries:
  Node: 22.6.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.1 // Latest available version is detected (15.0.1).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A
```


### Which area(s) are affected? (Select all that apply)

Module Resolution

### Which stage(s) are affected? (Select all that apply)

next build (local)

### Additional context

_No response_