Hello,
I have a Netlify function which makes use of file I upload next to function file.
This works only in production:
const credentials_path = './src/functions/create_project/credentials.json'
But when testing locally with Netlify Dev, I have to remove src
from the path above. This works only on localhost:
const credentials_path = './functions/create_project/credentials.json'
Is it possible to unify file path in both environments?
jen
January 15, 2021, 6:07pm
3
Hey there,
Netlify Dev bundles functions differently than we do when you deploy to Netlify. You may want to chime in on this related issue on the CLI, or open a new feature request if you feel it’s different enough from this one:
opened 09:11PM - 12 Jan 21 UTC
closed 02:18PM - 21 Jan 21 UTC
good first issue
type: bug
area: command: functions
**Describe the bug**
Having an NPM script which uses `netlify-lambda` and opt… ions that come **after** the functions source folder will incorrectly detect the option as the function source.
**To Reproduce**
Steps to reproduce the behavior:
1. Set up a new Netlify repo with `netlify-lambda` as a dependency
2. Add an NPM script, e.g. `functions:build` that runs netlify `netlify-lambda build` and passes an argument **after** specifying the functions source folder, e.g. `netlify-lambda build functions/src -c ./functions/webpack.config.js`
3. Run `netlify dev`, which will pick up the `functions:build` script
4. Notice that Netlify Dev logs "building functions from directory **./functions/webpack.config.js**"
5. Changes in the function source won't be picked up either, only changes to `./functions/webpack.config.js`
**Expected behavior**
The functions source directory should be able to be detected regardless of which spot any options passed to `netlify-lambda` are passed
**Additional context**
As `netlify-lambda build` allows any options to be placed either before or after the functions source folder itself, that should also work when used together with Netlify Dev.
The problem should be quite easily fixed by modifying the regex used here
https://github.com/netlify/cli/blob/305f8f4a92e030384dc58ae9d572a611880a7b7d/src/function-builder-detectors/netlify-lambda.js#L16
Happy to take a look at the regex and open a PR, just give me a shout
1 Like