Problem with FaunaDB function- import failure

Hi,

I’m playing around with functions and trying to do something simple but can’t seem to get it working. I’ve gotten two functions deployed, one works fine (simple “Hello, World”), now I’m trying to get a simple FaunaDB function working. I’ve created a database, gotten the key, and created the function. But, I’m getting an import failure right at the top:

{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'faunadb'\nRequire stack:\n- /var/task/faunatestreadall.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module 'faunadb'",
"Require stack:",
"- /var/task/faunatestreadall.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:1156:30)",
"    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)",
"    at Module.load (internal/modules/cjs/loader.js:1000:32)",
"    at Function.Module._load (internal/modules/cjs/loader.js:899:14)",
"    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)",
"    at internal/main/run_main_module.js:18:47"
]
}

Maybe I’m being stupid, but I should just need to add the .js file in my functions directory like the Hello, World function, right? But, it looks like FaunaDB isn’t available on AWS at runtime. Do I need to do anything to include it? I didn’t think so, and none of the examples I’ve found seems to spell it out… or I’m just an idiot :slight_smile:

Note that I haven’t posted the full function on purpose because at this point I don’t think it’s relevant, it’s dying on the first line, which is:

const faunadb = require("faunadb");

Anyone point me in the right direction? Thanks!

FYI, answered my own question: I needed to have a package.json file listing faunadb as a dependency, and then I needed to specify a build command that runs npm install. Once I did that, I got past the dependency issue (having another issue with the query, but that’s entirely on me).

Thanks, self! :slight_smile:

1 Like

awesome! thanks for sharing what you needed to do differently :smiley: :medal_sports:

thanks, that’s helped me but get a new authorization error, I’m new to faunadb and netlify function so if you can help me with. here is the function

https://dreamy-tesla-53a48b.netlify.app/.netlify/functions/users