I'm trying to use netlify and its lambda function feature to run a node function with dependencies. Based on https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget/ , I have in my functions/submission-created.js:
const fetch = require('node-fetch');
exports.handler = async event => {
const email = JSON.parse(event.body).payload.EMAIL
const asking = JSON.parse(event.body).payload.ASKING
console.log(`Recieved a submission: ${email}`)
....
When I look under my netlify websites functions tab (secreenshot above) , I see:
11:40:35 PM: 2020-12-02T04:40:35.092Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'node-fetch'
Require stack:
- /var/task/submission-created.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js","stack":["Runtime.ImportModuleError: Error: Cannot find module 'node-fetch'","Require stack:","- /var/task/submission-created.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js"," at _loadUserApp (/var/runtime/UserFunction.js:100:13)"," at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)"," at Object.<anonymous> (/var/runtime/index.js:43:30)"," at Module._compile (internal/modules/cjs/loader.js:1015:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)"," at Module.load (internal/modules/cjs/loader.js:879:32)"," at Function.Module._load (internal/modules/cjs/loader.js:724:14)"," at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)"," at internal/main/run_main_module.js:17:47"]}
my package.json (after running npm init):
{
"name": "site",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"node-fetch": "^2.6.1"
}
}
The package structure looks like:
here is the repo :
https://github.com/kc1/test2
I've tried putting the node modules folder and package.json in multiple places and repushing the repo, but I'm still getting the error above. What am I doing wrong?
EDIT:
please see Netlify: No build command found, continuing to publishing for new info on build process
See Question&Answers more detail:
os