felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
MIT License
342 stars 42 forks source link

Native node modules are not loaded correctly #48

Closed mihail-stanchev closed 9 years ago

mihail-stanchev commented 9 years ago

I have this situation: a sandboxed module loads sequelize, which in turn loads the sqlite3 module. sqlite3 has a native module (.node) implementation. Somewhere in the chain of calls to require sandboxed-module tries to compile the content of the native module as source code, which leads to an error, obviously.

I have worked around this issue locally by adding a check if the extension of the file to be loaded is ".node":

if (builtinModules.indexOf(request) >= 0 || path.extname(request) == ".node") {
   if (request in cache) return cache[request];
   return require(request);
}

I am happy to submit a pull request if you find this okay.

domenic commented 9 years ago

Pull request (with test!) welcome