how to import require.cache and require.resolve

  • Since i’m using module type in package.json or import instead of require.
  • how can i import require.cache and require.resolve
  • i’m trying to reload a file and update changes made.
// error: require is not defined
delete require.cache[require.resolve(`./index.js`)];
  • I tried till now
// This runs with no issues but doesn't update the changes.
import { resolve } from 'node:path';
const require = createRequire(import.meta.url);
delete require.cache[resolve(`./index.js`)];
  • without path
const require = createRequire(import.meta.url);
delete require.cache[require.resolve(`./index.js`)];
  • But this doen’t update the changes made in index.js

Expected Result

  • If i reload specific file and it should update the changes made to file (index.js).