Netlify Lambda doesn't include supporting files for Function

185 views Asked by At

I'm using Netlify Lambda to host a form on my website.

The form worked great but it was really messy.

To clean up the file I created a new file with the necessary functions and imported them into my form file. Now I have two files instead of one. The files are forms.js and formData.js. formData.js has the functions that forms.js depends on.

For some reason, my form doesn't work now. It's like the data isn't being imported.

Here is my folder structure:

src/functions/forms/forms.js
src/functions/forms/formData.js

netlify.toml file:

[build]
  command = "npm run build"
  functions = "functions"

Inside my forms.js file, I have imported the data from the formData.js file like this:

const data = require.resolve('./formData.js');
const { functionOne, functionTwo, functionThree, functionFour } = data;

I ran npm run build hoping the build would pick up the additional file, but nothing has happened and it doesn't work. Any advice?

Thanks in advance.

1

There are 1 answers

1
Abraham Labkovsky On

A bit more code might help, as well as a log.

It looks like you are using require.resolve which returns a string path. You cannot destructure a string to function definitions.

Can you try const { functionOne, functionTwo, functionThree, functionFour } = require('./formData.js');?

Can we assume you are, in fact calling these functions somewhere?