You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unsure of what the exact issue is and why it cannot find the modules node_modules when doing browserify build:
JAWS: -------------------------------------------
JAWS: Dashboard: Deploying Lambdas...
JAWS: -------------------------------------------
JAWS: Lambda Deployer: Packaging "lAwsmUsersCreate"...
JAWS: Lambda Deployer: Saving in dist dir /var/folders/9h/_6jlx37d1flfdfdf0z1v50r80000gn/T/lAwsmUsersCreate@1444044791712
JAWS: Getting ENV file from S3 bucket: jaws.dev.useast1.myapp-nj1ghi1x.com in us-east-1
Error running browserify bundle
{ [Error: Cannot find module 'bluebird' from '/private/var/folders/9h/_6jlx37d1flfdfdf0z1v50r80000gn/T/lAwsmUsersCreate@1444044791712/aws_modules/awsm-users/create']
ls /private/var/folders/9h/_6jlx37d1flfdfdf0z1v50r80000gn/T/lAwsmUsersCreate@1444044791712/node_modules/awsm-users/node_modules
bcryptjs bluebird debug dotenv jsonwebtoken moment node-uuid
But, your logic has to be moved to the lib folder. Particularly, your dependencies or they won't resolve. We're attempting to make the aws-modules more like regular modules and not editable templates. I didn't get very far with this in the above link but it shows off the pattern you will need.
So, your module's lib folder is where you write your logic and require all of your dependencies. In the awsm/lambda, you should not require those dependencies. Instead, awsm/lambda/files should contain basic scaffolding for others to get started and should require your aws-module only, and use that. In your aws-module, you expose functions/methods for awsm/lambda/files to use.
This is actually quite onerous. I can't just code up an endpoint: I have to code up a node module with an arbitrary opinionated structure just to write an endpoint.
Can we just make it so that I can install and require node_modules in the awsm folder?
Sometimes you don't want to make a reusable module to share, you just want to write some code....
@jwulf Could you clarify on "Can't code up an endpoint"? You can still code up a lambda function/endpoint without making a corresponding node_module. Just make sure your lambda's dependencies are in the root package.json, which is shared by all Lambdas.
This is a big decision. I'm very open to feedback here. Especially from you @jwulf!
When using the module create command you can create a module within your project without the need for an NPM module. As @ac360 mentioned, loading project dependencies from the aws_modules dir shouldn't be a problem and works the exact same way as for every other Node.js project. :)
l85m 13:21
how do you include external (non awsm) modules in JAWS? I'm requiring them as normal and it works when I jaws run, but jaws deploy is giving me this error:
dekz 13:36
you need to make your lambda code (index.js) a smal wrapper around your lib code
your code in lib can resolve the 3rd party requires
l85m 13:49
yep that's what I have now - there are no 3rd party requires in aws_modules, only in lib
I require lib like this var action = require('../../../index.js').updatecdr;
contents of ../../../index.js is exports.updatecdr = require('./lib/updatecdr.js');
dekz 13:50
and you did a npm install —save pg-bricks
l85m 13:50
yep ./node_modules has all the dependencies
including pg-bricks
second line of updatecdr.js is var db = require('pg-bricks').configure(constring);
dekz 13:56
whats in your handler.js file?
l85m 13:56
'use strict';
/**
* AWS Module: Action: Lambda Handler
* "Your lambda functions should be a thin wrapper around your own separate
* modules, to keep your code testable, reusable and AWS independent"
*/
require('jaws-core-js/env');
// Modularized Code
var action = require('./index.js');
// Lambda Handler
module.exports.handler = function(event, context) {
action.run(event, context, function(error, result) {
return context.done(error, result);
});
};
no worries, appreciate you trying to help
not really sure what the right structure is, the docs don't seem to have it
the folder structure completely excludes node_modules and lib
this one: https://github.com/jaws-framework/JAWS/blob/master/docs/project_structure.md
dekz 14:04
ah yes that is frustrating
l85m 14:05
I'll check out the browserify docs - I didn't really even know that browserify was doing the magic until you just said it
dekz 14:06
do you want to push your code some where @l85m, might get a chance to take a look at it later tonight
l85m 14:08
thanks for the offer @dekz - unfortunately there's some stuff in here we can't share right now but I will just go back to a non jaws approach for now and try and figure it out on monday. ping you back when I figure it out
thanks again for trying to help!
I ran some tests and I've noticed 2 problems, both related to Browserify:
If an NPM module has optional dependencies (for example, redis module has optional dependency on hiredis), the Browserify build fails when this dependency is not found. This can be solved by passing the ignoreMissing option to Browserify. (See PR: Let Browserify continue on missing optional dependencies (#201) #215)
To clarify things a bit more, you should be able to simply require node modules from JS files in the aws_modules directory in the usual way, i.e. you can simply do:
hi @laurentmeyer I used webpack with the 0.4 which helped me to debug the problem. now with serverless 0.5 I'm using browserify (only because the webpack plugin hasn't been updated yet) and you can find more info about this problem here serverless/serverless-runtime-babel#8
Activity
austencollins commentedon Oct 5, 2015
@dekz Sorry, I meant to share this with you last night: https://github.com/ac360/awsm-users/blob/master/lib/users.js
But, your logic has to be moved to the lib folder. Particularly, your dependencies or they won't resolve. We're attempting to make the aws-modules more like regular modules and not editable templates. I didn't get very far with this in the above link but it shows off the pattern you will need.
So, your module's
libfolder is where you write your logic and require all of your dependencies. In theawsm/lambda, you should not require those dependencies. Instead,awsm/lambda/filesshould contain basic scaffolding for others to get started and should require your aws-module only, and use that. In your aws-module, you expose functions/methods forawsm/lambda/filesto use.dekz commentedon Oct 5, 2015
That explains that, cheers Austen!
jwulf commentedon Oct 8, 2015
This is actually quite onerous. I can't just code up an endpoint: I have to code up a node module with an arbitrary opinionated structure just to write an endpoint.
Can we just make it so that I can install and require node_modules in the awsm folder?
Sometimes you don't want to make a reusable module to share, you just want to write some code....
austencollins commentedon Oct 8, 2015
@jwulf Could you clarify on "Can't code up an endpoint"? You can still code up a lambda function/endpoint without making a corresponding node_module. Just make sure your lambda's dependencies are in the root package.json, which is shared by all Lambdas.
This is a big decision. I'm very open to feedback here. Especially from you @jwulf!
joostfarla commentedon Oct 9, 2015
When using the
module createcommand you can create a module within your project without the need for an NPM module. As @ac360 mentioned, loading project dependencies from theaws_modulesdir shouldn't be a problem and works the exact same way as for every other Node.js project. :)eahefnawy commentedon Oct 9, 2015
Yep. I really like this design. Now it's both a template and an NPM. Whatever your project needs.
jwulf commentedon Oct 10, 2015
This is what I mean. From the JAWS Gitter today:
l85m 13:21how do you include external (non awsm) modules in JAWS? I'm requiring them as normal and it works when I jaws run, but jaws deploy is giving me this error:
dekz 13:36you need to make your lambda code (index.js) a smal wrapper around your lib code
your code in lib can resolve the 3rd party requires
l85m 13:49yep that's what I have now - there are no 3rd party requires in aws_modules, only in lib
I require lib like this
var action = require('../../../index.js').updatecdr;contents of
../../../index.jsisexports.updatecdr = require('./lib/updatecdr.js');dekz 13:50and you did a
npm install —save pg-bricksl85m 13:50yep
./node_moduleshas all the dependenciesincluding
pg-brickssecond line of
updatecdr.jsis vardb = require('pg-bricks').configure(constring);dekz 13:56whats in your
handler.jsfile?l85m 13:56here's
./index.jsdekz 13:58that
../../../index.jsis in your jaws project root?l85m 13:58yep
feels like there's a better way to do that which I'm missing
dekz 13:59move those functions into the
libfolderI’m not that familiar with how the Browserify build works though sorry
l85m 14:00this is what's in
../../../index.js:no worries, appreciate you trying to help
not really sure what the right structure is, the docs don't seem to have it
the folder structure completely excludes
node_modulesandlibthis one:
https://github.com/jaws-framework/JAWS/blob/master/docs/project_structure.mddekz 14:04ah yes that is frustrating
l85m 14:05I'll check out the browserify docs - I didn't really even know that browserify was doing the magic until you just said it
dekz 14:06do you want to push your code some where @l85m, might get a chance to take a look at it later tonight
l85m 14:08thanks for the offer @dekz - unfortunately there's some stuff in here we can't share right now but I will just go back to a non jaws approach for now and try and figure it out on monday. ping you back when I figure it out
thanks again for trying to help!
joostfarla commentedon Oct 10, 2015
I ran some tests and I've noticed 2 problems, both related to Browserify:
redismodule has optional dependency onhiredis), the Browserify build fails when this dependency is not found. This can be solved by passing theignoreMissingoption to Browserify. (See PR: Let Browserify continue on missing optional dependencies (#201) #215)pg-brickspackage, it has underlying dependencies which contain some require statements which break the Browserify build. I've submitted 2 PR's to fix this (Require statement breaks Browserify compatibility brianc/node-pg-types#43 and Require statements break Browserify compatibility brianc/node-postgres#875), but it might take some time before these changes are generally available inpg-bricks.To clarify things a bit more, you should be able to simply require node modules from JS files in the
aws_modulesdirectory in the usual way, i.e. you can simply do:There is no need to wrap stuff in an
index.jsfile, that's only required when creating reusable NPM modules.Better docs on these subjects have to be provided, this is on the roadmap!
Merge pull request #215 from joostfarla/deps
l85m commentedon Oct 11, 2015
@joostfarla - just to clarify, is this meant to reflect how things should work, or how they currently do?
Also thanks for looking into pg-bricks. I'll use your PR until it's merged.
joostfarla commentedon Oct 11, 2015
This is how things currently work!
thenikso commentedon Mar 22, 2016
Following up on this, I'm getting the error
Cannot find module '/local-folder/_meta/_tmp/graphql@1458678661120/node_modules/pgpass/lib/helper.jsboth if I use
pg-bricksorpg-promise. any idea? thanks!🌴 solved this, (I had to use https://github.com/asprouse/serverless-webpack-plugin to find the problem) which was in the
pgpass/lib/index.jstrying torequirea file using a constructed path. I edited the node_module itself.laurentmeyer commentedon Mar 24, 2016
@thenikso hey could you please explain the modification you did to the module? Did you end up using Browserify (= Optimizer) or Webpack?
Thanks
thenikso commentedon Mar 30, 2016
hi @laurentmeyer I used webpack with the 0.4 which helped me to debug the problem. now with serverless 0.5 I'm using browserify (only because the webpack plugin hasn't been updated yet) and you can find more info about this problem here serverless/serverless-runtime-babel#8