Skip to content

Required json file is not removed from cache, even after a re-install #3326

Closed
@serkanserttop

Description

@serkanserttop

We have this piece of code in our CLI tool:

  function getVersion() {
    return require('../../package.json').version;
  }

A customer experienced an issue where he re-installed a new version of our software via npm, and when he ran it, he saw that he was getting the package version from the older installation.
I can verify from his terminal log that the newer package was installed.
If it makes any difference, it is a globally installed tool.

I can have a workaround by manually deleting it from the cache.

  function getVersion() {
    //fixing Node bug
    var name = require.resolve('../../package.json');
    delete require.cache[name];
    return require('../../package.json').version;
  }

Is this a bug, or an expected behavior?
This was experienced in Node v4.1.2.
I don't know if it affects other versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions