1

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)

Currently my netlify.toml has only the following:

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

and my package.json:

"name": "test2",
"version": "1.0.0",
"description": "",
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "build": "npm run build"
},
"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"
}
}

What is the relationship between package.json and netlify.toml in the netlify build process (I'm primarily a python developer and fairly new to node ) ?

Dominik
  • 6,078
  • 8
  • 37
  • 61
user1592380
  • 34,265
  • 92
  • 284
  • 515
  • The package.json script `"build": "npm run build"` will call itself in an infinite loop – Dominik Dec 09 '20 at 21:26
  • Yes , that's what happened. (https://app.netlify.com/sites/inspiring-ardinghelli-4a4da5/deploys/5fd119b05df9b10007467752). Do I need it at all given "1:38:57 PM: Executing user command: npm install && npm run build" - which I assume comes from the toml file? " – user1592380 Dec 10 '20 at 00:03
  • from what I can see here the toml file is telling the computer to run `npm run build` and the package.json file is telling the computer to run `npm run build` resulting in an infinite loop. What you need to do is actually run something or disable the command... I can't know what to run as I don't know anything about your project – Dominik Dec 10 '20 at 00:05
  • I'm assuming you do have to run a build but what that command is I can't know. Could be a CRA build command or a babel build or something entirely different – Dominik Dec 10 '20 at 00:06

0 Answers0