pierrec / node-eval

Evaluate node require() module content directly
MIT License
93 stars 20 forks source link

Replace "require-like" by createRequire? #33

Open slorber opened 7 months ago

slorber commented 7 months ago

require-like uses Module._load, an API that is not supported by Bun (atm): https://github.com/oven-sh/bun/issues/5925

This led to bugs in Docusaurus Bun support: https://github.com/oven-sh/bun/issues/3426#issuecomment-1929173528

This can be prevented by using this Node API instead of the very old require-like code:

const module = require("module");

const sandbox = {
  require: module.createRequire(_filename);
}

This seems to be the "modern" way to achieve the same behavior, using a built-in API, and would get rid of a useless dependency. (and this would permit to use this lib in Bun, until they support the older Module apis)