Skip to content

Require of cached modules is not working after a while #55168

Open
@tMihaita

Description

@tMihaita

Version

18.20.4

Platform

Linux b3fb3508-30f0-4ff0-4220-0bc8 5.15.0-117-generic #127-Ubuntu SMP Fri Jul 5 20:13:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

What steps will reproduce the bug?

The issue we face happens as following:
During the runtime of our backend, we happen to need some code extensions which we basically download and save on the disk ( on demand ofc ), and after we got them in place we require them in the code using the filePath that is being returned by the function which does the download & save on disk. [Yes we know thats not safe, but that works for us right now]

Now, after some weeks or days even of the backend running, these demanded files that are can be found in the require.cache ( once we require the file the first time ) are getting somehow lost, or module.exports of that specific module gets lost.

How often does it reproduce? Is there a required condition?

Usually, we encounter this issue once every two weeks or similar. ( But from what our users report, its not always the same case )

What is the expected behavior? Why is that the expected behavior?

We expect the require(filePath) to return the actual functions and other things exposed via module.exports.

What do you see instead?

Instead, we basically see the following:
image
we also tried to see somehow the require(file)'s keys
image

The strange thing is, the file is on the disk, and actually has content in it ( even if in the following picture we dont actually see any module.exports, trust me, those are there )
image

While debugging, even if the file itself is on the disk, the debugger does not show it:
image


as for the require.cache here it is:
image

Additional information

I have to mention that usually, using delete require.cache(that require) and downloading the file again solves the issue, or just restarting the server itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    loadersIssues and PRs related to ES module loaders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions