Hi, everyone. Happy Friday!
I want to share with you a change to some internal implementation details of Netlify Functions that weβve recently rolled out.
Up until now, all function files were placed inside a src/
sub-directory when deployed. This meant that there was a mismatch in file paths between the local and production environments.
For example, imagine the following project structure:
my-project/
ββ netlify/
β ββ functions/
β β ββ my-function.js
β β ββ file-one.txt
ββ netlify.toml
When developing locally, file-one.txt
lives at {PROJECT ROOT}/netlify/functions/file-one.txt
, but when deployed to production its path would be {FUNCTION ROOT}/src/netlify/functions/file-one.txt
(note the extra src/
path segment).
This meant that if you wanted to dynamically reference this file, and you were constructing its path using something like process.cwd()
in Node, you would get inconsistent results between the local and production environments.
The fix we rolled out addresses this inconsistency and removes the extra src/
segment from the path, meaning that the file will live at {FUNCTION ROOT}/netlify/functions/file-one.txt
in production.
What this means for you
Nothing has changed in our public APIs or in the way files are referenced. For example, any files youβre referencing using relative paths (e.g. require('../../some-file.js')
) will continue to work in the same way.
This change should go unnoticed for the vast majority of users.
Only if you are using absolute paths starting with /var/task
you might need to update them. For example, a path like /var/task/src/some-file.js
must be changed to /var/task/some-file.js
.
I should add that if you are using these paths, you should find an alternative solution, because youβre relying on internal implementation details that are subject to change. If thatβs your case and you need help in finding alternative solutions, share your use case with us and weβll be glad to point you in the right direction.
Let me know if you have any questions about this. Thanks!