haseebnqureshi / serverless-hq

Serverless made quick & easy. This is your home base for quick & powerfully easy scaffolding for your next Serverless project.
MIT License
10 stars 1 forks source link

Do we need to explicitly require fs and path modules? #11

Closed haseebnqureshi closed 7 years ago

haseebnqureshi commented 7 years ago

Normally they come standard with nodejs, but this error makes me think otherwise. This came from our deployment to AWS:

module initialization error: Error
    at Error (native)
    at Object.fs.readdirSync (fs.js:808:18)
    at Object.__dirname.requireModulesFromDir (/var/task/node_modules/shared/serverless-hq/index.js:43:12)
    at Object.<anonymous> (/var/task/node_modules/shared/serverless-hq/index.js:101:14)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
haseebnqureshi commented 7 years ago

This one was CRAZY. The fs module runs statically, and so if you still need to read the directory contents of dynamically set paths, you require a commonjs module dynamically, and then have that module read its dir contents using fs.