Modify netlify.toml [functions] for [build] and [dev]

Hi there! I’m running into an issue related to symlinks being incorrect when running netlify functions:server but are correct when deployed to Netlify. Locally, it crashes before the background function has a chance to load.

◈ Failed to load function publish-charts-background: ENOENT: no such file or directory, symlink '../acorn/bin/acorn' -> '/Users/jacqueschrag/Documents/projects/axios-hermes-svelte/.netlify/functions-serve/publish-charts-background/netlify/functions/chart_template/node_modules/.bin/acorn'

 ›   Error: Netlify CLI has terminated unexpectedly
This is a problem with the Netlify CLI, not with your application.
If you recently updated the CLI, consider reverting to an older version by running:

npm install -g netlify-cli@VERSION

In my setup, I have a directory /chart_template that sits at the project root that I’m referencing in my /netlify/functions/publish-charts-background.mjs function.

I’m struggling to find a workaround that doesn’t require me to manually copy & paste /chart_template into the generated /.netlify/functions-serve/publish-charts-background/ directory.

I’ve noticed that if I remove the included_files setting from my netlify.toml file, it works just fine locally - but then will break in production.

[dev]
  targetPort = 5173

[build]
  command = 'npm run build'
  publish = 'build'

[functions]
  node_bundler = "esbuild"
  included_files = ["chart_template/**"]
  external_node_modules = ["esbuild", "esbuild-sass-plugin"]
  directory = "netlify/functions"

I’m wondering if there is a way for me to only set the included_files property in the production environment, and not have it on dev. Something like this, maybe?

[dev]
  targetPort = 5173

[build]
  command = 'npm run build'
  publish = 'build'

[functions]
  node_bundler = "esbuild"
  included_files = ["chart_template/**"]
  external_node_modules = ["esbuild", "esbuild-sass-plugin"]
  directory = "netlify/functions"

[functions.dev]
  included_files = []

Thanks in advance for any guidance here!

There’s no way to do that. However, the devs will check on the GitHub issue and try to fix that so this won’t be needed.

Thanks for the quick response. Just to be clear, there’s no way to use the deploy contexts configuration to help achieve what I want?

Alternatively, is there a solution where I can have an entire netlify.toml file for dev and publish a different one for production?

Ultimately I’d love for this to get fixed in the CLI, but this issue has been open for several months now, so I’m really hoping to find a workable solution I can use in the meantime.

I don’t know if this is the “right” way to do this, but this is the solution that worked for me.

I ended up making a local plugin that sets what I need in production.

export const onPreBuild = function ({ netlifyConfig }) {
	console.log('Plugin to dynamically set functions included_files');
	netlifyConfig.functions['*'].included_files = ['chart_template/**'];

	console.log(netlifyConfig.functions);
};

My netlify.toml now looks like this:

[dev]
  targetPort = 5173

[build]
  command = 'echo "{\"VITE_FUNCTION_URL\": \"$URL\"}" > env.json && npm run build'
  publish = 'build'

[context.deploy-preview]
  command = 'echo "{\"VITE_FUNCTION_URL\": \"$DEPLOY_PRIME_URL\"}" > env.json && npm run build'

[functions]
  node_bundler = "esbuild"
  external_node_modules = ["esbuild", "esbuild-sass-plugin"]
  directory = "netlify/functions"

[[plugins]]
  package = "/plugins/netlify-plugin-functions"

I won’t call this the right way, but it’d definitely a good workaround till the actual issue is fixed.