node require需要注意的缓存问题 发表于 2017-09-18 require 会优先从cache中读取文件 1234567891011121314151617/* add.js*/let value = 0;module.exports = () => { console.log(value ++);};/* main.js*/add_1 = require('./add.js');add = require('./add.js');add_1(); //1add_1(); //2add(); //3 Object.keys(require.cache).forEach(key => console.log(require.cache[key].exports === add);); //true