Fixing accidental detection of require.js as common js

I changed to code to check for common js by looking for exports and module instead. Also, would it be possible to require fs inside the function where it's used?