Skip to content
Browse files

Make browser safe

  • Loading branch information...
1 parent cdc8413 commit 4cb4d77bfb488d75a23425468245484b2aa50173 @creationix committed Mar 27, 2012
Showing with 5 additions and 2 deletions.
  1. +5 −2 module.js
View
7 module.js
@@ -10,7 +10,7 @@ define = function define(name, fn) {
defs[name] = fn;
}
-var realRequire = require;
+var realRequire = typeof require !== "undefined" && require;
// The first time a module is used, it's description is executed and cached.
require = function require(name) {
if (modules.hasOwnProperty(name)) return modules[name];
@@ -21,7 +21,10 @@ require = function require(name) {
fn(module, exports);
return modules[name] = module.exports;
}
- return realRequire(name);
+ if (realRequire) {
+ return realRequire(name);
+ }
+ throw new Error("Can't find module " + name);
}
}());

0 comments on commit 4cb4d77

Please sign in to comment.
Something went wrong with that request. Please try again.