babel-runtime sometimes includes the node_modules and other directories when it shouldn't
Opened this issue · 1 comments
Hello,
The babel-runtime is awesome (and much easier to test code with than the optimizer-plugin). However, after migrating to the babel-runtime, I noticed that my lambdas are significantly larger than with the optimizer plugin.
In one instance, my lambda was around 210 KB with the optimizer and became over 6 MB when using the babel runtime. After investigation, it appears to be because the babel runtime was including the node_modules
and some other directories (like coverage and test reports) generated by my build process. When I manually remove the extra directories and deploy, the lambda still runs fine, so these are not needed and should be excluded by default.
I have set-up a sample repository at https://github.com/dijitalmunky/serverless-example. The master
branch is a plain old serverless project with no plugins, the sls-optimizer-plugin branch is the same, but with the optimizer configured and, finally, the sls-runtime-babel branch is the master with the just serverless-runtime-babel installed and configured.
Sizes I was getting for deployed lambdas are as follows:
- master - 4.9MB
- sls-runtime-babel - 1010.9kB
- sls-optimizer-plugin - 28.1kB
I am having difficulties with this as well. I have noticed my _meta/_tmp directory will get up to 250MB. Which is odd because my whole project directory including node_modules and source control is only 48MB.
It seems to make a copy of every file and directory: .git, test, node_modules.
This prevents me from deploying. I get this error message:
Serverless: Deploying functions in "dev" to the following regions: us-west-2
Serverless: ------------------------
Serverless: Failed to deploy the following functions in "dev" to the following regions:
Serverless: us-west-2 ------------------------
Serverless: auth-login: ENOSPC: no space left on device, write
UPDATE:
I tracked my problem down to my file structure which was setup like this:
project/
auth/
login/
handler.js
lib/
crypto.js
node_modules/
test/
This was a problem because my s-function.json had the handler
set as auth/login/handler.handler
and was including everything in the root of my project like the node_modules
and was recursively including the _meta directory. This was causing an infinite loop ending up with a mega directory like _meta/_tmp/_meta/_tmp/_meta/_tmp forever.
I was able to resolve my issue by modifying my project structure to to include a parent directory to hold all handler required code.
project/
api/
auth/
login/
handler.js
lib/
crypto.js
node_modules/
test/