0

enter image description here

I'm trying to use netlify and its lambda function feature to run a node function . Based on https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget/ .

I'm having trouble getting node modules to work (see ImportModuleError","errorMessage":"Error: Cannot find module while using Netlify lambda functions with dependencies)

I just realized that there is a Deploy log which contains:

2:53:02 PM: Build ready to start
12:53:03 PM: build-image version: 8e31xxxxxxx
12:53:03 PM: build-image tag: v2.8.2
12:53:03 PM: buildbot version: 45cd000yyyyyyy
12:53:03 PM: Fetching cached dependencies
12:53:03 PM: Starting to download cache of 7.3MB
12:53:03 PM: Finished downloading cache in 291.717877ms
12:53:03 PM: Starting to extract cache
12:53:04 PM: Finished extracting cache in 85.783157ms
12:53:04 PM: Finished fetching cache in 381.732805ms
12:53:04 PM: Starting to prepare the repo for build
12:53:04 PM: Preparing Git Reference refs/heads/master
12:53:05 PM: Found netlify.toml. Overriding site configuration
12:53:05 PM: Different functions path detected, going to use the one specified in the toml file: './functions' versus '' in the site
12:53:05 PM: No build command found, continuing to publishing
12:53:05 PM: Starting to deploy site from '/'

My netlify.toml has only the following:

[build]
  functions = "./functions"

should I add something else to allow usage of node dependencies?

edit:

my package.json:

"name": "test2",
"version": "1.0.0",
"description": "",
"scripts": {
 "test": "echo \"Error: no test specified\" && exit 1",

 },
 "repository": {
 "type": "git",
 "url": "git+https://github.com/kc1/test2.git"
 },
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/kc1/test2/issues"
 } ,
"homepage": "https://github.com/kc1/test2#readme",
"dependencies": {
"dotenv": "^8.2.0",
"node-fetch": "^2.6.1"

} }

I realized I don't have a build script. What should you recommend? I tried build: 'npm run build', but this led to a failure to build..

https://app.netlify.com/sites/inspiring-ardinghelli-4a4da5/deploys/5fd02bbd61df720008e0a041
user1592380
  • 34,265
  • 92
  • 284
  • 515

1 Answers1

1

This is from a blog post with Express but it should be similar.

netlify.toml looks like this:

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

https://www.netlify.com/blog/2018/09/13/how-to-run-express.js-apps-with-netlify-functions/

https://github.com/neverendingqs/netlify-express/blob/master/netlify.toml

Make sure your package.json actually has a build command.

https://stackoverflow.com/a/53311374/3850405

Ogglas
  • 62,132
  • 37
  • 328
  • 418
  • If you actually took the time to read the link I provided for `package.json` you would see that your `package.json` does not include a build command. `npm run build: runs the build field from the package.json scripts field.` https://stackoverflow.com/a/53311374/3850405 `package.json` from the Github I linked to for example: https://github.com/neverendingqs/netlify-express/blob/master/package.json – Ogglas Dec 09 '20 at 08:08
  • I read all the links. I'm coming from a python background and don't have a great understanding of the package.json and the build process in node. I realize that my package.json does not include a build script, but I don't understand what to use for the build script in it. I've tried adding "build": "npm run build" to package.json produces https://app.netlify.com/sites/inspiring-ardinghelli-4a4da5/deploys/5fd119b05df9b10007467752 . What would you recommend here? – user1592380 Dec 09 '20 at 18:41
  • `npm run build` maps to `package.json` -> `scripts` -> `build`. Given the example they have a build script that does `"build": "netlify-lambda build express",`. Look at this complete example instead and understand everything there before you proceed would be my best advice. https://gist.github.com/skatkov/b524a6e60a5313acc4d299471a2a3902 – Ogglas Dec 09 '20 at 22:37