Hi,
I have seen similar existing issues but I can't seem to make it work. I would like your advice if what im doing is right.
This is what my folder structure looks like:
.
โโโ admin.env
โโโ functions
โย ย โโโ geospatial
โย ย ย ย โโโ get_bounding_coordinates
โย ย ย ย โโโ event.json
โย ย ย ย โโโ handler.js
โย ย ย ย โโโ s-function.json
โโโ _meta
โย ย โโโ resources
โย ย โย ย โโโ s-resources-cf-dev-uswest2.json
โย ย โโโ variables
โย ย โโโ s-variables-common.json
โย ย โโโ s-variables-dev.json
โย ย โโโ s-variables-dev-uswest2.json
โโโ node_modules
โย ย โโโ geopoint
โย ย โโโ geopoint.js
โย ย โโโ index.js
โย ย โโโ LICENSE
โย ย โโโ package.json
โย ย โโโ README.md
โย ย โโโ test
โย ย โโโ test.accessors.js
โย ย โโโ test.bounding.js
โย ย โโโ test.constructor.js
โย ย โโโ test.conversions.js
โย ย โโโ test.distance.js
โโโ package.json
โโโ s-project.json
โโโ s-resources-cf.json
โโโ s-templates.json
First on the root of my project folder, I ran "npm install geopoint --save". it added "dependencies": { "geopoint": "^1.0.1" }
on package.json. It also added the npm_modules folder and its contents.
In functions/geospatial/get_bounding_coordinates/handler.js, i declared var geopoint = require('geopoint');
The error is that lambda returns:
{
"errorMessage": "Cannot find module 'geopoint'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:276:25)",
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)",
"Object.<anonymous> (/var/task/handler.js:2:16)",
"Module._compile (module.js:409:26)",
"Object.Module._extensions..js (module.js:416:10)",
"Module.load (module.js:343:32)",
"Function.Module._load (module.js:300:12)",
"Module.require (module.js:353:17)"
]
}
Is there something wrong with my implementation?
In your s-function.json you have to specify your handler as functions/geospatial/get_bounding_coordinates/handler.handler
. This will set the function root to the directory containing the node_modules
. From my experience it is better to have the function root in a subfolder of the project, as otherwise all serverless plugins will be also packaged.
Hi! Thank you very much for the answer! It worked! What do you mean by setting the function root in the subfolder? is it forexample putting the node_modules folder and package.json file under functions folder?
Hi @taptip would be great if we could move this discussion into our Gitter chat so we can have support questions there. We will make our documentation a lot better to cover this in the future.
I will close the issue for now to mark it as resolved.
Most helpful comment
In your s-function.json you have to specify your handler as
functions/geospatial/get_bounding_coordinates/handler.handler
. This will set the function root to the directory containing thenode_modules
. From my experience it is better to have the function root in a subfolder of the project, as otherwise all serverless plugins will be also packaged.