I've been looking create-react-app's configuration files.
After ejecting, we can see require.cache is used in config/env.js file.
// config/env.js
"use strict";
const fs = require("fs");
const path = require("path");
const paths = require("./paths");
// Make sure that including paths.js after env.js will read .env variables.
delete require.cache[require.resolve("./paths")];
...
I quite cannot understand why that require.cache is used. I know what require.cache is for and does, but cannot understand why this is used in this case.
I've made config/test.js file and compared the output.
const a = require('./paths')
const b = require('./env')
console.log("A", a)
console.log("B", b)
const c = require('./env')
const d = require('./paths')
console.log("C", c)
console.log("D", d)
node config/test.js
As expected, those are the same. So what is the purpose of using require.cache in the config/env.js file?