Skip to content

Require cache problem/question #3144

Closed
Closed
@nairihar

Description

@nairihar
  • Node.js v12.18.1:
  • OS: MacOS
  • Scope runtime:

I'm trying to create a JSON file after running node, and then require it.

This code works fine.

Screen Shot 2020-12-26 at 3 34 22 PM

When I tried to require the file inside try-catch before creation, I wasn't able to require it after creation.

Screen Shot 2020-12-26 at 3 36 48 PM

Error:
Screen Shot 2020-12-26 at 3 38 40 PM

This error related to my second requires, since the first one is inside trying catch. Meanwhile, my file was created.

Screen Shot 2020-12-26 at 3 39 33 PM

I thought there is a cache, so I need to delete the value for my file from require.cache.

Screen Shot 2020-12-26 at 3 40 55 PM

But it didn't help:

Screen Shot 2020-12-26 at 3 41 11 PM

Could you please help me to understand how Node.js works in this case? And how can I solve this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions