So I am installing FaunaDB. I have this function:
‘use strict’;
const faunadb = require(‘faunadb’);
/* configure faunaDB Client with our secret */
const q = faunadb.query;
const client = new faunadb.Client({
secret: 'SECRET KEY'
});
/* create a user in FaunaDB that can connect from the browser */
function createUser(userid, name, email) {
return client.query(
q.Create(q.Class('users'), {
data: {
id: userid,
name: name,
email: email
}
})
);
}
exports.handler = function(event, context, callback) {
createUser(event.queryStringParameters.userid,event.queryStringParameters.name,event.queryStringParameters.email)
.then(key =>
callback(null, {
statusCode: 200,
body: 'Done'
})
)
.catch(e => {
console.error(e);
callback(null, {
statusCode: 500,
body: JSON.stringify({
error: e
})
});
});
}
And I have this package.json:
{
“name”: “login-curso”,
“version”: “1”,
“dependencies”: {
“faunadb”: “^2.5.2”
}
}
However, every time I run my function I get:
{“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘faunadb’\nRequire stack:\n- /var/task/register.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js”,“trace”:[“Runtime.ImportModuleError: Error: Cannot find module ‘faunadb’”,“Require stack:”,“- /var/task/register.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. (/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"]}