Skip to content

Unable to find dependencies #201

Closed
Closed

Description

@dekz

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

https://github.com/dekz/awsm-users/tree/1.3

Activity

  1. austencollins commented on Oct 5, 2015

    @austencollins
    Member

    @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 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.

  2. dekz commented on Oct 5, 2015

    @dekz
    ContributorAuthor

    That explains that, cheers Austen!

  3. jwulf commented on Oct 8, 2015

    @jwulf

    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....

  4. austencollins commented on Oct 8, 2015

    @austencollins
    Member

    @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!

  5. joostfarla commented on Oct 9, 2015

    @joostfarla
    Contributor

    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. :)

  6. eahefnawy commented on Oct 9, 2015

    @eahefnawy
    Contributor

    Yep. I really like this design. Now it's both a template and an NPM. Whatever your project needs.

  7. jwulf commented on Oct 10, 2015

    @jwulf

    This is what I mean. From the JAWS Gitter today:

    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:

     {
      "errorMessage": "Cannot find module '/private/var/folders/9n/bsnlhf010h310zdh9pcb5s0x6ng6pf/T/lJasperUpdatecdr@1444446978230/node_modules/pg-bricks/node_modules/pg/lib/client'",
      "errorType": "Error",
      "stackTrace": [
        "Function.Module._resolveFilename (module.js:338:15)",
        "Function.Module._load (module.js:280:25)",
        "Module.require (module.js:364:17)",
        "require (module.js:380:17)",
        "i (/var/task/aws_modules/jasper/updatecdr/handler.js:1:497)",
        "/var/task/aws_modules/jasper/updatecdr/handler.js:1:688",
        "Object.<anonymous> (/var/task/aws_modules/jasper/updatecdr/handler.js:2:16197)",
        "Object.events (/var/task/aws_modules/jasper/updatecdr/handler.js:2:17253)",
        "i (/var/task/aws_modules/jasper/updatecdr/handler.js:1:637)",
        "/var/task/aws_modules/jasper/updatecdr/handler.js:1:688"
      ]
    }
    

    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);
      });
    };
    

    here's ./index.js

     var action = require('../../../index.js').updatecdr;
    
    module.exports.run = function(event, context, cb) {
      return action(event, cb)
    };
    

    dekz 13:58
    that ../../../index.js is in your jaws project root?

    l85m 13:58
    yep
    feels like there's a better way to do that which I'm missing

    dekz 13:59
    move those functions into the lib folder
    I’m not that familiar with how the Browserify build works though sorry

    l85m 14:00
    this is what's in ../../../index.js:

     exports.updatecdr = require('./lib/updatecdr.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_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!

  8. joostfarla commented on Oct 10, 2015

    @joostfarla
    Contributor

    I ran some tests and I've noticed 2 problems, both related to Browserify:

    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:

    var db = require('pg-bricks');
    

    There is no need to wrap stuff in an index.js file, that's only required when creating reusable NPM modules.

    Better docs on these subjects have to be provided, this is on the roadmap!

  9. added a commit that references this issue on Oct 10, 2015
  10. l85m commented on Oct 11, 2015

    @l85m

    @joostfarla - just to clarify, is this meant to reflect how things should work, or how they currently do?

    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

    Also thanks for looking into pg-bricks. I'll use your PR until it's merged.

  11. joostfarla commented on Oct 11, 2015

    @joostfarla
    Contributor

    just to clarify, is this meant to reflect how things should work, or how they currently do?

    This is how things currently work!

  12. thenikso commented on Mar 22, 2016

    @thenikso

    Following up on this, I'm getting the error Cannot find module '/local-folder/_meta/_tmp/graphql@1458678661120/node_modules/pgpass/lib/helper.js

    both if I use pg-bricks or pg-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.js trying to require a file using a constructed path. I edited the node_module itself.

  13. laurentmeyer commented on Mar 24, 2016

    @laurentmeyer

    @thenikso hey could you please explain the modification you did to the module? Did you end up using Browserify (= Optimizer) or Webpack?

    Thanks

  14. thenikso commented on Mar 30, 2016

    @thenikso

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions