You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Required json file is not removed from cache, even after a re-install #3326
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.
This is the expected behavior, NOT a bug, if the json file was required at least once before the file was modified in the file system it will use the memcached version next times. In your workaround you are just updating the cache, another solution would be to request the file directly with the fs module and parse it or manage it as you want:
function getVersion() {
return JSON.parse(fs.readFileSync('/path/to/file.json', 'utf8')).version;
}
Activity
micnic commentedon Oct 12, 2015
This is the expected behavior, NOT a bug, if the json file was required at least once before the file was modified in the file system it will use the memcached version next times. In your workaround you are just updating the cache, another solution would be to request the file directly with the
fsmodule and parse it or manage it as you want: