Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to unload ? #22

Open
LucaGabi opened this issue Aug 4, 2018 · 2 comments
Open

How to unload ? #22

LucaGabi opened this issue Aug 4, 2018 · 2 comments

Comments

@LucaGabi
Copy link

LucaGabi commented Aug 4, 2018

Thanks, it works great, but how to unload the loaded code ?

@ORESoftware
Copy link

good question, not sure if it's necessary. I checked the require cache:

console.log(require.cache);

and I don't see it in there. I think it will only be in the cache if you load the module with require(). But in this case we aren't using require.

@ORESoftware
Copy link

ORESoftware commented Nov 22, 2018

as a simple example:

var Module = require('module');

function requireFromString(src, filename) {
  var m = new Module(filename, null);
  m._compile(src, filename);
  m.loaded = true;
  m.filename = filename;
  return m;
}

console.log(
  requireFromString(
    'module.exports = { test: 1}',
    '<some-uuid>'
  )
);

const x = require('<some-uuid>');  // this will throw an error
console.log(x);

console.log(
  'cache:',
  require.cache
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants